61 |
|
|
62 |
<!-- Origen de datos que srive para calcular el total facturado --> |
<!-- Origen de datos que srive para calcular el total facturado --> |
63 |
|
|
64 |
<datasource name="invTotDataSource" database="papo" |
<datasource name="productInvoiceDataSource" database="papo" |
65 |
table="_entity_data, own_document, own_item, own_proditem, _price_data, own_item_tax" |
table="_entity_data, own_document, own_item, own_product_item, _price_data, own_item_tax" |
66 |
order_by="own_proditem.id"> |
order_by="own_product_item.id"> |
67 |
<condition> |
<condition> |
68 |
<and> |
<and> |
69 |
<eq> |
<eq> |
70 |
<!-- Aqui se refiere al cliente --> |
<!-- Aqui se refiere al cliente --> |
71 |
<cfield name="_entity_data._table"/> |
<cfield name="_entity_data.id"/> |
72 |
<cfield name="own_document.recipient"/> |
<cfield name="own_document.recipient"/> |
73 |
</eq> |
</eq> |
74 |
<eq> |
<eq> |
77 |
</eq> |
</eq> |
78 |
<eq> |
<eq> |
79 |
<cfield name="own_item.id"/> |
<cfield name="own_item.id"/> |
80 |
<cfield name="own_proditem.own_item"/> |
<cfield name="own_product_item.own_item"/> |
81 |
</eq> |
</eq> |
82 |
<eq> |
<eq> |
83 |
<cfield name="own_proditem.price"/> |
<cfield name="own_product_item.price"/> |
84 |
<cfield name="_price_data.id"/> |
<cfield name="_price_data.id"/> |
85 |
</eq> |
</eq> |
86 |
<eq> |
<eq> |
95 |
</condition> |
</condition> |
96 |
</datasource> |
</datasource> |
97 |
|
|
98 |
|
<datasource name="serviceInvoiceDataSource" database="papo" |
99 |
|
table="_entity_data, own_document, own_item, own_service_item, own_item_tax" |
100 |
|
order_by="own_service_item.id"> |
101 |
|
<condition> |
102 |
|
<and> |
103 |
|
<eq> |
104 |
|
<!-- Aqui se refiere al cliente --> |
105 |
|
<cfield name="_entity_data.id"/> |
106 |
|
<cfield name="own_document.recipient"/> |
107 |
|
</eq> |
108 |
|
<eq> |
109 |
|
<cfield name="own_document.id"/> |
110 |
|
<cfield name="own_item.own_document"/> |
111 |
|
</eq> |
112 |
|
<eq> |
113 |
|
<cfield name="own_item.id"/> |
114 |
|
<cfield name="own_service_item.own_item"/> |
115 |
|
</eq> |
116 |
|
<eq> |
117 |
|
<cfield name="own_item.id"/> |
118 |
|
<cfield name="own_item_tax.own_item"/> |
119 |
|
</eq> |
120 |
|
<eq> |
121 |
|
<cfield name="own_document.own_document_type"/> |
122 |
|
<cconst value="1"/> |
123 |
|
</eq> |
124 |
|
</and> |
125 |
|
</condition> |
126 |
|
</datasource> |
127 |
|
|
128 |
<datasource name="invTaxTotDataSource" database="papo" |
<datasource name="invTaxTotDataSource" database="papo" |
129 |
table="own_document, own_document_tax"> |
table="own_document, own_document_tax"> |
159 |
|
|
160 |
<datasource name="ownItemDataSource" database="papo" detaillink="own_item.own_document" |
<datasource name="ownItemDataSource" database="papo" detaillink="own_item.own_document" |
161 |
master="ownDocumentDataSource" masterlink="id" |
master="ownDocumentDataSource" masterlink="id" |
162 |
table="own_item, own_proditem, own_item_tax"> |
table="own_item, own_product_item, own_item_tax"> |
163 |
<condition> |
<condition> |
164 |
<and> |
<and> |
165 |
<eq> |
<eq> |
166 |
<cfield name="own_item.id"/> |
<cfield name="own_item.id"/> |
167 |
<cfield name="own_proditem.own_item"/> |
<cfield name="own_product_item.own_item"/> |
168 |
</eq> |
</eq> |
169 |
<eq> |
<eq> |
170 |
<cfield name="own_item.id"/> |
<cfield name="own_item.id"/> |
198 |
<datasource name="invoiceToPayedDataSource" cache="1"/> |
<datasource name="invoiceToPayedDataSource" cache="1"/> |
199 |
|
|
200 |
<trigger type="NAMED" name="showInvoiceToPayTrigger"><![CDATA[ |
<trigger type="NAMED" name="showInvoiceToPayTrigger"><![CDATA[ |
201 |
|
|
202 |
total = 0.0 |
total = 0.0 |
203 |
if str(ownDocumentBlock.clientRecipientBox.clientEntry): |
if str(ownDocumentBlock.clientRecipientBox.clientEntry): |
204 |
import gnue.common.GConditions as GConditions |
import gnue.common.GConditions as GConditions |
205 |
import hack |
import hack |
206 |
|
|
207 |
cond = GConditions.GCondition() |
condProductInvoice = GConditions.GCondition() |
208 |
balance = 0 |
condServiceInvoice = GConditions.GCondition() |
209 |
|
condPay = GConditions.GCondition() |
210 |
eq = GConditions.GCeq(cond) |
|
211 |
GConditions.GCField(eq,"own_document.recipient") |
eq = GConditions.GCeq(condProductInvoice) |
212 |
|
GConditions.GCField(eq,"_entity_data._table") |
213 |
|
GConditions.GCConst(eq,str(ownDocumentBlock.clientRecipientBox.clientEntry)) |
214 |
|
|
215 |
|
eq = GConditions.GCeq(condServiceInvoice) |
216 |
|
GConditions.GCField(eq,"_entity_data._table") |
217 |
|
GConditions.GCConst(eq,str(ownDocumentBlock.clientRecipientBox.clientEntry)) |
218 |
|
|
219 |
|
eq = GConditions.GCeq(condPay) |
220 |
|
GConditions.GCField(eq,"_entity_data._table") |
221 |
GConditions.GCConst(eq,str(ownDocumentBlock.clientRecipientBox.clientEntry)) |
GConditions.GCConst(eq,str(ownDocumentBlock.clientRecipientBox.clientEntry)) |
222 |
|
|
223 |
# Calculo del total facturado |
# Calculo del total facturado por Productos |
224 |
rs = invTotDataSource.createResultSet(cond) |
productInvoiceResultSet = productInvoiceDataSource.createResultSet(condProductInvoice) |
225 |
more = rs.firstRecord() |
more = productInvoiceResultSet.firstRecord() |
|
|
|
|
while more: |
|
|
invTotal = 0 |
|
|
itemTot = 0 |
|
|
currOwnDoc = rs.current.getField("own_document.id") |
|
|
while rs.current.getField("own_document.id") == currOwnDoc and more: |
|
|
itemTot += hack.a2f(rs.current.getField("own_proditem.qty")) * \ |
|
|
hack.a2f(rs.current.getField("_price_data.unit_price")) - \ |
|
|
hack.a2f(rs.current.getField("own_item.bonus")) - \ |
|
|
hack.a2f(rs.current.getField("own_item.discount")) |
|
|
taxTot = 0 |
|
|
currItem = rs.current.getField("own_item.id") |
|
|
while rs.current.getField("own_item.id") == currItem and more: |
|
|
taxTot += itemTot * (hack.a2f(rs.current.getField("own_item_tax.amount")) / 100) |
|
|
more = rs.nextRecord() |
|
|
invTotal += taxTot |
|
226 |
|
|
227 |
invTotal += itemTot - hack.a2f(rs.current.getField("own_document.bonus")) |
while more: |
228 |
# Calcula los impuestos del documento en si |
invoiceTotal = 0 |
229 |
|
currOwnDoc = productInvoiceResultSet.current.getField("own_document.id") |
230 |
|
while productInvoiceResultSet.current.getField("own_document.id") == currOwnDoc and more: |
231 |
|
lQty = hack.a2f(productInvoiceResultSet.current.getField("own_product_item.qty")) |
232 |
|
lUnitPrice = hack.a2f(productInvoiceResultSet.current.getField("_price_data.unit_price")) |
233 |
|
lBonus = hack.a2f(productInvoiceResultSet.current.getField("own_item.bonus")) |
234 |
|
lDiscount = hack.a2f(productInvoiceResultSet.current.getField("own_item.discount")) |
235 |
|
item = lQty * lUnitPrice - lBonus - lDiscount |
236 |
|
#print "qty %d * unit_price %d - bonus %d - discount %d = %d " % (lQty, lUnitPrice, lBonus, lDiscount, lQty * lUnitPrice - lBonus - lDiscount) |
237 |
|
itemTaxTotal = 0 |
238 |
|
currItem = productInvoiceResultSet.current.getField("own_item.id") |
239 |
|
while productInvoiceResultSet.current.getField("own_item.id") == currItem and more: |
240 |
|
itemTaxTotal += item * (hack.a2f(productInvoiceResultSet.current.getField("own_item_tax.amount"))/100) |
241 |
|
more = productInvoiceResultSet.nextRecord() |
242 |
|
invoiceTotal += item + itemTaxTotal |
243 |
|
# Calcula los impuestos del documento en si |
244 |
odt_rs = invTaxTotDataSource.createResultSet({"own_document.id":currOwnDoc}) |
odt_rs = invTaxTotDataSource.createResultSet({"own_document.id":currOwnDoc}) |
245 |
odt_more = odt_rs.firstRecord() |
odt_more = odt_rs.firstRecord() |
246 |
while odt_more: |
while odt_more: |
247 |
invTotal += hack.a2f(odt_rs.current.getField("own_document_tax.amount")) |
invoiceTotal += hack.a2f(odt_rs.current.getField("own_document_tax.amount")) |
248 |
odt_more = odt_rs.nextRecord() |
odt_more = odt_rs.nextRecord() |
249 |
|
|
250 |
tmpInvToPayedBlock.idEntry = rs.current.getField("own_document.id") |
tmpInvToPayedBlock.idEntry = productInvoiceResultSet.current.getField("own_document.id") |
251 |
tmpInvToPayedBlock.dateEntry = rs.current.getField("own_document.date") |
tmpInvToPayedBlock.dateEntry = productInvoiceResultSet.current.getField("own_document.date") |
252 |
tmpInvToPayedBlock.amountEntry = str(invTotal) |
tmpInvToPayedBlock.amountEntry = str(invoiceTotal) |
253 |
tmpInvToPayedBlock.payedEntry = "0.0" |
tmpInvToPayedBlock.payedEntry = "0.0" |
254 |
tmpInvToPayedBlock.newRecord() |
tmpInvToPayedBlock.newRecord() |
255 |
|
|
256 |
|
# Calculo del total facturado |
257 |
|
## Factura de servicios |
258 |
|
serviceInvoiceResultSet= serviceInvoiceDataSource.createResultSet (condServiceInvoice) |
259 |
|
more= serviceInvoiceResultSet.firstRecord () |
260 |
|
|
261 |
|
# por todos los documentos post-checkpoint (si no hay, desde el principio) |
262 |
|
# print "calc 4" |
263 |
|
while more: |
264 |
|
invoiceTotal = 0 |
265 |
|
currentOwnDocument= serviceInvoiceResultSet.current.getField ("own_document.id") |
266 |
|
|
267 |
|
# por todos los items del documento |
268 |
|
# print "calc 5: [%s] %d" % (currentOwnDocument, spentTotal) |
269 |
|
while serviceInvoiceResultSet.current.getField ("own_document.id")==currentOwnDocument and more: |
270 |
|
item = hack.a2f(serviceInvoiceResultSet.current.getField ("own_service_item.amount")) |
271 |
|
currentItem= serviceInvoiceResultSet.current.getField ("own_item.id") |
272 |
|
itemTaxTotal = 0 |
273 |
|
# por todos los impuestos del item |
274 |
|
# print "calc 6: [%s:%s] %d" % (currentOwnDocument, currentItem, invoiceTotal) |
275 |
|
while serviceInvoiceResultSet.current.getField ("own_item.id")==currentItem and more: |
276 |
|
# calculate the item price exactly as I do in the other trigger |
277 |
|
# not revised yet, but I think it was like this |
278 |
|
taxAmount = hack.a2f(serviceInvoiceResultSet.current.getField ("own_item_tax.amount")) |
279 |
|
itemTaxTotal += round(item * (taxAmount/100), 2) |
280 |
|
more= serviceInvoiceResultSet.nextRecord () |
281 |
|
# print "calc 7: %d:%d" % (item, itemTaxTotal) |
282 |
|
|
283 |
|
invoiceTotal += item + itemTaxTotal |
284 |
|
|
285 |
|
tmpInvToPayedBlock.idEntry = serviceInvoiceResultSet.current.getField("own_document.id") |
286 |
|
tmpInvToPayedBlock.dateEntry = serviceInvoiceResultSet.current.getField("own_document.date") |
287 |
|
tmpInvToPayedBlock.amountEntry = str(invoiceTotal) |
288 |
|
tmpInvToPayedBlock.payedEntry = "0.0" |
289 |
|
tmpInvToPayedBlock.newRecord() |
290 |
|
|
291 |
|
|
292 |
# Busco las que ya han sido pagadas |
# Busco las que ya han sido pagadas |
293 |
rs = payTotDataSource.createResultSet(cond) |
rs = payTotDataSource.createResultSet(condPay) |
294 |
more = rs.firstRecord() |
more = rs.firstRecord() |
295 |
while more: |
while more: |
296 |
rc = tmpInvToPayedBlock.getRecordCount() |
rc = tmpInvToPayedBlock.getRecordCount() |
324 |
<trigger type="NAMED" name="cancelTrigger"><![CDATA[ |
<trigger type="NAMED" name="cancelTrigger"><![CDATA[ |
325 |
import hack |
import hack |
326 |
|
|
|
invoiceToPayedBlock.processRollback() |
|
327 |
ownDocumentBlock.processRollback() |
ownDocumentBlock.processRollback() |
328 |
tmpInvToPayedBlock.processRollback() |
tmpInvToPayedBlock.processRollback() |
329 |
|
invoiceToPayedBlock.processRollback() |
330 |
|
proceedingBlock.processRollback() |
331 |
|
currencyMovementBlock.processRollback() |
332 |
|
movementBlock.processRollback() |
333 |
|
ownDocumentProceedingBlock.processRollback() |
334 |
|
|
335 |
]]></trigger> |
]]></trigger> |
336 |
|
|
338 |
import hack |
import hack |
339 |
|
|
340 |
proceedingBlock.processRollback() |
proceedingBlock.processRollback() |
341 |
|
currencyMovementBlock.processRollback() |
342 |
|
movementBlock.processRollback() |
343 |
|
ownDocumentProceedingBlock.processRollback() |
344 |
|
|
345 |
|
ownDocumentBlock.idEntry.autofillBySequence('own_document_id_seq') |
346 |
|
ownDocumentBlock.typeEntry = "3" |
347 |
|
|
348 |
proceedingBlock.idEntry.autofillBySequence('proceeding_id_seq') |
proceedingBlock.idEntry.autofillBySequence('proceeding_id_seq') |
349 |
proceedingBlock.dateEntry = proceedingDataSource.getTimeStamp() |
proceedingBlock.dateEntry = proceedingDataSource.getTimeStamp() |
350 |
|
|
351 |
|
currencyMovementBlock.proceedingEntry = str(proceedingBlock.idEntry) |
352 |
|
currencyMovementBlock.movementTypeEntry = "" # Revisar com queda esto |
353 |
|
currencyMovementBlock.currencyTypeEntry = "1" |
354 |
|
currencyMovementBlock.amountEntry = str(invoiceToPayedBlock.invoiceBox.totalEntry) |
355 |
|
|
356 |
|
movementBlock.proceedingEntry = str(proceedingBlock.idEntry) |
357 |
|
movementBlock.movementTypeEntry = "1" # Revisar com queda esto |
358 |
|
movementBlock.amountEntry = str(invoiceToPayedBlock.invoiceBox.totalEntry) |
359 |
|
|
360 |
|
ownDocumentProceedingBlock.proceedingEntry = str(proceedingBlock.idEntry) |
361 |
|
ownDocumentProceedingBlock.ownDocumentEntry = str(ownDocumentBlock.idEntry) |
362 |
|
ownDocumentProceedingBlock.amountEntry = str(invoiceToPayedBlock.invoiceBox.totalEntry) |
363 |
|
|
364 |
rc = invoiceToPayedBlock.getRecordCount() |
rc = invoiceToPayedBlock.getRecordCount() |
365 |
for recNum in range(rc): |
for recNum in range(rc): |
366 |
invoiceToPayedBlock.jumpRecord(recNum) |
invoiceToPayedBlock.jumpRecord(recNum) |
367 |
if hack.a2f(invoiceToPayedBlock.invoiceBox.payedEntry) > 0: |
if hack.a2f(invoiceToPayedBlock.invoiceBox.payEntry) > 0: |
368 |
ownDocumentProceedingBlock.processRollback() |
ownDocumentProceedingBlock.proceedingEntry = str(invoiceToPayedBlock.invoiceBox.idEntry) |
369 |
ownDocumentBlock.idEntry.autofillBySequence('own_document_id_seq') |
ownDocumentProceedingBlock.ownDocumentEntry = str(ownDocumentBlock.idEntry) |
370 |
ownDocumentBlock.typeEntry = "2" |
ownDocumentProceedingBlock.amountEntry = str(invoiceToPayedBlock.invoiceBox.payEntry) |
371 |
|
|
372 |
ownDocumentProceedingBlock.proceedingEntry = str(proceedingBlock.idEntry) |
ownDocumentBlock.commit() |
373 |
ownDocumentProceedingBlock.ownDocumentEntry = str(ownDocumentBlock.idEntry) |
callTrigger('cancelTrigger') |
374 |
ownDocumentProceedingBlock.amountEntry = str(payBlock.cashEntry) |
ownDocumentBlock.clientRecipientBox.dateEntry = ownDocumentDataSource.getTimeStamp() |
|
|
|
|
currencyMovementBlock.processRollback() |
|
|
currencyMovementBlock.proceedingEntry = str(proceedingBlock.idEntry) |
|
|
currencyMovementBlock.movementTypeEntry = "" # Revisar com queda esto |
|
|
currencyMovementBlock.currencyTypeEntry = "1" |
|
|
currencyMovementBlock.amountEntry = str(payBlock.cashEntry) |
|
375 |
|
|
376 |
]]></trigger> |
]]></trigger> |
377 |
|
|
389 |
|
|
390 |
]]></trigger> |
]]></trigger> |
391 |
|
|
392 |
|
<trigger type="On-Startup"><![CDATA[ |
393 |
|
ownDocumentBlock.clientRecipientBox.dateEntry = ownDocumentDataSource.getTimeStamp() |
394 |
|
]]></trigger> |
395 |
|
|
396 |
<page name="Emision de Recibos"> |
<page name="Emision de Recibos"> |
397 |
|
|
398 |
<block datasource="ownDocumentDataSource" name="ownDocumentBlock"> |
<block datasource="ownDocumentDataSource" name="ownDocumentBlock"> |
403 |
<entry x="1" y="2" field="recipient" name="clientEntry" |
<entry x="1" y="2" field="recipient" name="clientEntry" |
404 |
width="40" style="dropdown" foreign_key="clientDataSource._entity_data._table" |
width="40" style="dropdown" foreign_key="clientDataSource._entity_data._table" |
405 |
foreign_key_description="_entity_data.name"/> |
foreign_key_description="_entity_data.name"/> |
406 |
|
<label name="dateLbl" rows="1" text="Fecha" x="1" y="7" /> |
407 |
|
<entry field="date" name="dateEntry" style="label" readonly="" typecast="date" |
408 |
|
rows="1" width="24" x="7" y="7"/> |
409 |
<button name="showInvoicesButton" trigger="showInvoiceToPayTrigger" |
<button name="showInvoicesButton" trigger="showInvoiceToPayTrigger" |
410 |
label="Facturas Pendientes" width="20" height="1" x="42" y="2"/> |
label="Facturas Pendientes" width="20" height="1" x="42" y="2"/> |
411 |
</box> |
</box> |
469 |
x="1" y="1" width="12"/> |
x="1" y="1" width="12"/> |
470 |
<entry name="amountEntry" field="movement.amount" hidden="" x="1" y="1" width="12"/> |
<entry name="amountEntry" field="movement.amount" hidden="" x="1" y="1" width="12"/> |
471 |
</block> |
</block> |
472 |
|
<block name="proceedingBlock" datasource="proceedingDataSource"> |
473 |
|
<entry name="idEntry" field="id" hidden="" x="1" y="1" width="12"/> |
474 |
|
<entry name="dateEntry" field="date" hidden="" x="1" y="1" width="12"/> |
475 |
|
</block> |
476 |
|
|
477 |
|
|
478 |
</page> |
</page> |