/[papo]/papo/forms/productInvoice.neb
ViewVC logotype

Diff of /papo/forms/productInvoice.neb

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.39 by jlenton, Tue Sep 16 19:01:03 2003 UTC revision 1.40 by apronotti, Thu Sep 25 20:19:20 2003 UTC
# Line 7  Line 7 
7      my $uniqed=0;      my $uniqed=0;
8    </neb:Block>    </neb:Block>
9    
10    <datasource name="tmpValuesDataSource" cache="1"/>  <neb:Sub neb:src="own_document.nebc"
11      document_name="Factura"
12    <datasource name="prodSearchDataSource" cache="1"/>  document_type_A="4"
13    <datasource name="prodResultDataSource" cache="1"/>  document_type_B="8"
14    document_type_C="9"
15    stock_alta="stockSubstractTrigger"
16    <datasource name="ownOrganizationDataSource" database="papo"  stock_borrado="stockAddTrigger"
17      table="_entity_data, _own_entity_data, _organization_data, _persona_tax_profile_data, _tax_profile_data">  />
     <condition>  
       <and>  
         <!-- uniones del objeto n-1 -->  
         <eq>  
           <cfield name="_own_entity_data._table"/>  
           <cfield name="_organization_data.own_entity"/>  
         </eq>  
         <eq>  
           <cfield name="_entity_data._table"/>  
           <cfield name="_own_entity_data.entity"/>  
         </eq>  
         <eq>  
          <cfield name="_entity_data._table"/>  
          <cfield name="_persona_tax_profile_data.persona"/>  
         </eq>  
         <eq>  
           <cfield name="_tax_profile_data._table"/>  
           <cfield name="_persona_tax_profile_data.tax_profile"/>  
         </eq>  
         <eq>  
           <cfield name="_tax_profile_data.tax"/>  
           <cconst value="1"/> <!-- IVA -->  
         </eq>  
         <!-- history tables = null n -->  
         <null>  
           <cfield name="_entity_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_own_entity_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_organization_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_persona_tax_profile_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_tax_profile_data._end_t"/>  
         </null>  
         <!--busco el 1 -->  
         <eq>  
           <cfield name="organization.id"/>  
           <cconst value="1"/>  
         </eq>  
       </and>  
     </condition>  
   </datasource>  
   
   <!--   Origen de datos que sirve para seleccionar el cleinte al que se le -->  
   <!--   va a facturar   -->  
   <datasource name="clientDataSource" database="papo"  
               table="_entity_data, _alien_entity_data, _persona_data, _client_data,  
                      _price_type_data, _persona_tax_profile_data, _tax_profile_data, _tax_data">  
     <condition>  
       <and>  
         <eq>  
           <cfield name="_entity_data._table"/>  
           <cfield name="_alien_entity_data.entity"/>  
         </eq>  
         <eq>  
           <cfield name="_alien_entity_data._table"/>  
           <cfield name="_persona_data.alien_entity"/>  
         </eq>  
         <eq>  
           <cfield name="_persona_data._table"/>  
           <cfield name="_client_data.persona"/>  
         </eq>  
         <eq>  
          <cfield name="_price_type_data._table"/>  
           <cfield name="_client_data.price_type"/>  
         </eq>  
         <eq>  
          <cfield name="_entity_data._table"/>  
          <cfield name="_persona_tax_profile_data.persona"/>  
         </eq>  
         <eq>  
           <cfield name="_tax_profile_data._table"/>  
          <cfield name="_persona_tax_profile_data.tax_profile"/>  
         </eq>  
         <eq>  
          <cfield name="_tax_data._table"/>  
           <cfield name="_tax_profile_data.tax"/>  
         </eq>  
         <eq>  
          <cfield name="_tax_data._table"/>  
          <cconst value="1"/>  
         </eq>  
         <null>  
           <cfield name="_entity_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_alien_entity_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_persona_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_client_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_price_type_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_persona_tax_profile_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_tax_profile_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_tax_data._end_t"/>  
         </null>  
       </and>  
     </condition>  
   </datasource>  
   
   <datasource name="clientSearchDataSource" database="papo"  
               table="_entity_data, _alien_entity_data, _persona_data, _client_data, entity_type_uid_conf,  
                      _entity_uid_data" order_by="_entity_data.name">  
     <condition>  
       <and>  
         <eq>  
           <cfield name="_entity_data._table"/>  
           <cfield name="_alien_entity_data.entity"/>  
         </eq>  
         <eq>  
           <cfield name="_alien_entity_data._table"/>  
           <cfield name="_persona_data.alien_entity"/>  
         </eq>  
         <eq>  
           <cfield name="_persona_data._table"/>  
           <cfield name="_client_data.persona"/>  
         </eq>  
         <eq>  
          <cfield name="_entity_data._table"/>  
           <cfield name="_entity_uid_data.entity"/>  
         </eq>  
         <eq>  
          <cconst value="7"/>  
          <cfield name="entity_type_uid_conf.entity_type"/>  
         </eq>  
         <eq>  
          <cfield name="_entity_uid_data.entity_uid_type"/>  
          <cfield name="entity_type_uid_conf.entity_uid_type"/>  
         </eq>  
         <null>  
           <cfield name="_entity_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_alien_entity_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_persona_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_client_data._end_t"/>  
         </null>  
         <null>  
           <cfield name="_entity_uid_data._end_t"/>  
         </null>  
       </and>  
     </condition>  
   </datasource>  
   
   <!-- Origen de datos que srive para calcular el total facturado -->  
   <datasource name="productInvoiceTotalDataSource" database="papo"  
               table="_entity_data, own_document" >  
     <condition>  
       <and>  
         <eq>  
           <!-- Aqui se refiere al cliente  -->  
           <cfield name="_entity_data.id"/>  
           <cfield name="own_document.recipient"/>  
         </eq>  
         <or>  
           <eq>  
             <cfield name="own_document.own_document_type"/>  
             <cconst value="4"/> <!-- Factura tipo A -->  
           </eq>  
           <eq>  
             <cfield name="own_document.own_document_type"/>  
             <cconst value="8"/> <!-- Factura tipo B -->  
           </eq>  
           <eq>  
             <cfield name="own_document.own_document_type"/>  
             <cconst value="9"/> <!-- Factura tipo C -->  
           </eq>  
         </or>  
      </and>  
     </condition>  
   </datasource>  
   
   <!-- Origen de datos que srive para calcular los impuestos del la factura -->  
   <datasource name="ownDocumentTaxTotDataSource" database="papo"  
               table="own_document, own_document_tax">  
     <condition>  
       <eq>  
         <cfield name="own_document.id"/>  
         <cfield name="own_document_tax.own_document"/>  
       </eq>  
     </condition>  
   </datasource>  
   
   <!-- Origen de datos que srive para calcular el total facturado -->  
   <datasource name="productCreditNoteTotalDataSource" database="papo"  
               table="_entity_data">  
     <condition>  
       <and>  
         <eq>  
           <!-- Aqui se refiere al cliente  -->  
           <cfield name="_entity_data.id"/>  
           <cfield name="own_document.recipient"/>  
         </eq>  
         <or>  
           <eq>  
             <cfield name="own_document.own_document_type"/>  
             <cconst value="14"/> <!-- Nota de Crédito tipo A -->  
           </eq>  
           <eq>  
             <cfield name="own_document.own_document_type"/>  
             <cconst value="15"/> <!-- Nota de Crédito tipo B -->  
           </eq>  
           <eq>  
             <cfield name="own_document.own_document_type"/>  
             <cconst value="16"/> <!-- Nota de Crédito tipo C -->  
           </eq>  
         </or>  
      </and>  
     </condition>  
   </datasource>  
   
   <!-- Origen de datos que srive para calcular el total adeudado -->  
   <datasource name="paidTotalDataSource" database="papo" table="_entity_data, own_document, own_document_proceeding">  
     <condition>  
       <and>  
         <eq>  
           <!-- Aqui se refiere al cliente  -->  
           <cfield name="_entity_data.id"/>  
           <cfield name="own_document.recipient"/>  
         </eq>  
         <eq>  
           <cfield name="own_document.id"/>  
           <cfield name="own_document_proceeding.own_document"/>  
         </eq>  
         <and>  
           <or>  
             <eq>  
               <cfield name="own_document.own_document_type"/>  
               <cconst value="4"/>  
             </eq>  
             <eq>  
               <cfield name="own_document.own_document_type"/>  
               <cconst value="8"/>  
             </eq>  
             <eq>  
               <cfield name="own_document.own_document_type"/>  
               <cconst value="9"/>  
             </eq>  
           </or>  
         </and>  
       </and>  
     </condition>  
   </datasource>  
   
   <datasource name="priceDataSource" database="papo" table="_price_data" />  
   
   <!--   Origen de datos que contiene el encabezado de la factura   -->  
   <datasource database="papo" name="ownDocumentDataSource" table="own_document"  
     order_by="date" />  
   
 <!--   Origen de datos que sirve para consultar el limite de crédito -->  
 <!--   asignado al cliente que se le factura -->  
   
   <datasource name="tlCreditLimit1DataSource" database="papo"  
     table="_entity_data, _credit_limit_data">  
     <condition>  
     <and>  
       <eq>  
         <cfield name="_entity_data._table"/>  
         <cfield name="_credit_limit_data.entity"/>  
       </eq>  
       <eq>  
         <cfield name="_credit_limit_data.movement_type"/>  
         <cconst value="1"/>  
       </eq>  
       <null>  
          <cfield name="_credit_limit_data._end_t"/>  
       </null>  
     </and>  
     </condition>  
   </datasource>  
   
   <datasource name="creditLimit1DataSource" database="papo"  
     table="_credit_limit_data">  
     <condition>  
     <and>  
       <eq>  
         <cfield name="_credit_limit_data.movement_type"/>  
         <cconst value="1"/>  
       </eq>  
       <null>  
          <cfield name="_credit_limit_data._end_t"/>  
       </null>  
     </and>  
     </condition>  
   </datasource>  
   
   <!--   Origen de datos que contiene los items de la factura -->  
   <datasource  name="ownItemDataSource" database="papo" detaillink="own_item.own_document"  
      master="ownDocumentDataSource" masterlink="id"  
      table="own_item, own_product_item">  
     <condition>  
       <and>  
         <eq>  
           <cfield name="own_item.id"/>  
           <cfield name="own_product_item.own_item"/>  
         </eq>  
         <!--  <eq> -->  
         <!--    <cfield name="own_item.id"/> -->  
         <!--    <cfield name="own_item_tax.own_item"/> -->  
         <!--  </eq> -->  
         <!--  <eq> -->  
         <!--            <cfield name="own_item_tax.tax"/> -->  
         <!--            <cconst value="1"/> -->  
         <!--          </eq> -->  
       </and>  
     </condition>  
   </datasource>  
   
   
   <!--=== TRIGGERS ===-->  
   <trigger name="startUp" type="On-Startup">  
     tmpValuesDataSource.priceTypeId = None  
     tmpValuesDataSource.priceWithIva = 0  
       
     ownOrganizationBlock.clear()  
     ownOrganizationBlock.initQuery()  
     ownOrganizationBlock.processQuery()  
     print "iva condition" , str(ownOrganizationBlock.condIVAEntry)  
     print "entity id", str(ownOrganizationBlock.ownOrganizationIdEntry)  
     tmpValuesDataSource.ownOrganizationId = str(ownOrganizationBlock.ownOrganizationIdEntry)  
     tmpValuesDataSource.ownIVACond = str(ownOrganizationBlock.condIVAEntry)  
     tmpBlock.tmpDateEntry = ownDocumentDataSource.getTimeStamp()  
   </trigger>  
   
   <trigger name="changePriceWithIvaTrigger" type="NAMED"><![CDATA[  
     import hack  
       
     if len(str(ownDocAuxBlock.withIvaEntry)) and int(str(ownDocAuxBlock.withIvaEntry)) != tmpValuesDataSource.priceWithIva:  
       print "cambio"  
       lWithIva = int(str(ownDocAuxBlock.withIvaEntry))  
       lRecordCount = ownItemBlock.getRecordCount()  
       for recNum in range(lRecordCount):  
         ownItemBlock.jumpRecord(recNum)  
         if lWithIva:  
           ownItemBlock.unitPriceAuxEntry = hack.a2f(ownItemBlock.unitPriceEntry,4)*round(1+hack.a2f(ownItemBlock.ivaEntry,4)/100,4)  
         else:  
           ownItemBlock.unitPriceAuxEntry = hack.a2f(ownItemBlock.unitPriceEntry,4)/round(1+hack.a2f(ownItemBlock.ivaEntry,4)/100,4)  
   
     tmpValuesDataSource.priceWithIva = int(str(ownDocAuxBlock.withIvaEntry))  
   ]]></trigger>  
   
   <trigger name="setUnitPriceTrigger" type="NAMED">  
     import hack  
   
     if len(str(ownDocAuxBlock.withIvaEntry)) and \  
        len(str(ownItemBlock.unitPriceAuxEntry)) and \  
        len(str(ownItemBlock.ivaEntry)):  
       if int(str(ownDocAuxBlock.withIvaEntry)):  
         ownItemBlock.unitPriceEntry = hack.a2f(ownItemBlock.unitPriceAuxEntry,4)/ round(1+hack.a2f(ownItemBlock.ivaEntry,4)/100,4)  
       else:  
         ownItemBlock.unitPriceEntry = str(ownItemBlock.unitPriceAuxEntry)  
   </trigger>  
   
   <trigger name="recalcTotalTrigger" type="NAMED"><![CDATA[  
     import hack  
     totalBlock.totalEntry = hack.a2f(totalBlock.netoEntry)+hack.a2f(totalBlock.ivaEntry)  
     payBlock.cashEntry = hack.a2f(totalBlock.totalEntry,2)  
   ]]></trigger>  
   
   <trigger name="clientCallFormTrigger" type="NAMED"><![CDATA[  
     runForm('client.gfd')  
   ]]></trigger>  
   
   <trigger name="prodCallFormTrigger" type="NAMED"><![CDATA[  
     runForm('product.gfd')  
   ]]></trigger>  
   
   <trigger name="setInvoiceType" type="NAMED"><![CDATA[  
     invoiceType = str(ownDocumentBlock.invoiceTypeEntry).strip().lower()  
     if invoiceType == 'a':  
       ownDocumentBlock.typeEntry = '4'  
     elif invoiceType == 'b':  
       ownDocumentBlock.typeEntry = '8'  
     elif invoiceType == 'c':  
       ownDocumentBlock.typeEntry = '9'  
     else:  
       ownDocumentBlock.typeEntry = ''  
   ]]></trigger>  
   
   <trigger name="invoiceTypeValidation" type="NAMED"><![CDATA[  
     if str(ownDocumentBlock.invoiceTypeEntry).strip().lower() not in ('a','b','c'):  
       genericBox('El tipo de factura es incorrecto',['Aceptar'])  
       ownDocumentBlock.invoiceTypeEntry = ""  
     else:  
       ownDocumentBlock.invoiceTypeEntry = str(ownDocumentBlock.invoiceTypeEntry).strip().upper()  
   
     callTrigger('setInvoiceType')  
     callTrigger('searchNextInvoiceNumber')  
   ]]></trigger>  
   
   <neb:Sub neb:src="wait.nebc"/>  
   
   <trigger name="invoiceOkTrigger" type="NAMED"><![CDATA[  
   
     # print "Cantidad de Registros: ", ownItemBlock.getRecordCount()  
     # print "Leng Product Name: ", len(ownItemBlock.prodNameSEntry)  
     if ownItemBlock.getRecordCount() > 0 and len(ownItemBlock.prodNameSEntry) > 0:  
         if not str(ownDocumentBlock.invoiceTypeEntry):  
             genericBox("Falta el tipo de factura",["Aceptar"])  
         else:  
             setFocus(currencyTypeBlock.currencyBox.payEntry)  
             callTrigger('currencyWorkTrigger')  
   
   ]]></trigger>  
   
   <trigger name="commitTrigger" type="NAMED">  
     import hack  
   
     ownDocumentBlock.numberEntry = str(ownPosDocumentBlock.documentNumberEntry)  
     #cargo pos  
     ownDocumentBlock.ownPosEntityIdEntry =   str(ownPosBlock.ownPosEntityIdEntry)  
     #/cargo pos  
     ownDocumentBlock.dueDateEntry = str(payBlock.dateEntry)  
     ownDocumentBlock.dateEntry = str(tmpBlock.tmpDateEntry)  
     if len(ownDocumentBlock.dateEntry) == 0:  
         ownDocumentBlock.dateEntry = ownDocumentDataSource.getTimeStamp()  
   
     
     from gnue.common.GDataObjects import ConnectionError as DBError  
     try:  
         postChangeAdvance = 0  
         ownDocumentBlock.postChanges()  
         postChangeAdvance = 1  
         ownPosDocumentBlock.documentNumberEntry.postAtomicModify (lambda x: int(x)+1)  
         postChangeAdvance = 2  
         proceedingBlock.postChanges()  
         #cargo documento de retenciones  
         callTrigger('retentionCommitTrigger')  
         callTrigger('proceedingCommitTrigger')  
   
         postChangeAdvance = 5  
         #lOwnDocId = str(ownDocumentBlock.idEntry)  
         #if stock by invoice  
   
         if  str(ownPosBlock.stockByInvoice) == "1":  
             print "llamado al trigger"  
             callTrigger('stockSubstractTrigger')  
         callTrigger('taxFillTrigger')  
         ownItemTaxBlock.postChanges()  
         ownDocumentTaxTotalBlock.postChanges()  
           
         commitConnection()  
     except DBError, err:  
         rollbackConnection()  
         message = ["la Factura","el número de la Factura","el procedimiento General",  
                   "el procedimiento de la Factura","las monedas de pago de la Factura",  
                   "el stock" ]  
         genericBox("Hay problemas para grabar "+message[postChangeAdvance]+"\n"+str(err),['Aceptar'])  
         # this one's called from the print trigger, so let it know something went wrong  
         raise  
   
     tmpValuesDataSource.priceWithIva = 0  
     setFocus(ownItemBlock.prodCodeSEntry)  
   </trigger>  
   
   <trigger name="rollbackTrigger" type="NAMED">  
     tmpValuesDataSource.priceTypeId = None  
     tmpValuesDataSource.priceWithIva = 0  
     clear()  
   
     tmpBlock.tmpDateEntry = ownDocumentDataSource.getTimeStamp()  
     #setFocus(ownDocumentBlock.clientCodeEntry)  
   </trigger>  
   
   <trigger name="quitTrigger" type="NAMED">  
     callTrigger('rollbackTrigger')  
     ownDocumentBlock.clear()  
     exit()  
   </trigger>  
   
   <!--  Este trigger clacula el total facturado -->  
   <trigger name="totalCalcTrigger" type="NAMED">  
     import hack  
   
     lQty = hack.a2f(ownItemBlock.qtyEntry,4)  
     lBonus = hack.a2f(ownItemBlock.bonusEntry,4)  
     lDiscount = hack.a2f(ownItemBlock.discountEntry,4)  
     lUnitPrice = hack.a2f(ownItemBlock.unitPriceEntry,4)  
   
     lItemPrice = round((lQty * lUnitPrice) - lBonus - lDiscount,2)  
   
     # lo traigo de tax_formula  
     #ivaSourceCode = str(tmpValuesDataSource.IVAGraft)  
   
     #amount = lItemPrice  
     #taxPercent = hack.a2f(ownItemBlock.ivaEntry,4)  
   
     #exec(ivaSourceCode)  
     #aca debo cargarlo en item tax  
     #ownItemBlock.taxAmountEntry = hack.a2f(graft(ownIVACond,alienIVACond,amount,taxPercent),4)  
     # IVA  
     lTTax = hack.a2f(totalBlock.ivaEntry,2)  
     amount = lItemPrice  
     taxPercent = hack.a2f(ownItemBlock.ivaEntry,2)  
     #print "iva fmla",str(tmpValuesDataSource.IVAGraft)  
     #print "iva RNI fmla",tmpValuesDataSource.IVARNIGraft  
     if str(tmpValuesDataSource.IVAGraft) != "None":  
         ivaSourceCode=str(tmpValuesDataSource.IVAGraft)  
         exec(ivaSourceCode)  
         lTTax -= hack.a2f(ownItemBlock.ivaAmountEntry,2)  
         ownItemBlock.ivaAmountEntry = hack.a2f(graft(amount,taxPercent),4)  
         lTTax += hack.a2f(ownItemBlock.ivaAmountEntry,2)  
     if str(tmpValuesDataSource.IVARNIGraft) != "None":  
         print "hay iva RNI"  
         #if not ownItemIVARNIBlock.getCurrentRecord().isEmpty():  
         #    ownItemIVARNIBlock.newRecord()  
         ivaRNISourceCode=str(tmpValuesDataSource.IVARNIGraft)  
         exec(ivaRNISourceCode)  
         lTTax -= hack.a2f(ownItemBlock.ivaRNIAmountEntry,4)  
         ownItemBlock.ivaRNIAmountEntry = hack.a2f(graft(amount,taxPercent),4)  
         lTTax += hack.a2f(ownItemBlock.ivaRNIAmountEntry,4)  
     ownItemBlock.itemNetoEntry = lItemPrice  
     ownItemBlock.itemTotalEntry = lItemPrice + hack.a2f(ownItemBlock.ivaRNIAmountEntry,2)+hack.a2f(ownItemBlock.ivaAmountEntry,2)  
       
     #sumo el total del documento  
       
     lTNeto = 0  
       
   
     lRecords = ownItemDataSource.getRecords()  
     for index in range(len(lRecords)):  
       lRecord = lRecords[index]  
       lQty = hack.a2f(lRecord.getField("own_product_item.qty"),4)  
       #print "cantidad: ",lQty  
       lBonus = hack.a2f(lRecord.getField("own_item.bonus"),4)  
       lDiscount = hack.a2f(lRecord.getField("own_item.discount"),4)  
       lUnitPrice = hack.a2f(lRecord.getField("own_product_item.unit_price"),4)  
       lItemPrice = round((lQty * lUnitPrice) - lBonus - lDiscount,2)  
       lTNeto += lItemPrice  
       #lTTax += hack.a2f(lRecord.getField("own_item_tax.amount"),4)  
   
     ownDocumentBlock.netTotalEntry = str(round(lTNeto,2))  
     totalBlock.netoEntry = str(round(lTNeto,2))  
     ownDocumentBlock.taxTotalEntry = str(round(lTTax,2))  
     totalBlock.ivaEntry = str(round(lTTax,2))  
     totalBlock.totalEntry = str(round(lTNeto+lTTax,2))  
     payBlock.cashEntry = str(round(lTNeto+lTTax,2))  
     payBlock.ctaCteEntry = "0.0"  
   </trigger>  
   
   
 <trigger  name="alertOfDespatchNoteTrigger" type="NAMED">  
     if str(ownDocumentBlock.relatedToEntry)and (str(totalBlock.printDespatchNote) == "1") :  
         genericBox("Solo se incluira como relacionado el remito generado\n",['Aceptar'])  
 </trigger>  
   
 <trigger  name="invoiceForDespatchNoteTrigger" type="NAMED">  
     print "volvi"        
     import hack  
     reportNo= str(ownDocumentBlock.typeEntry)  
     #print 'here nos iva cond _ ell iva cond: %s, %s' % (str(tmpValuesDataSource.alienIVACond), str(tmpValuesDataSource.ownIVACond))  
     if str(tmpValuesDataSource.alienIVACond)=='2' and str(tmpValuesDataSource.ownIVACond)=='1':  
       # hack to use alternative report and print config  
       reportNo= '4_and_half'  
     report='productInvoice-%s' % reportNo  
     print 'here: %s' % reportNo  
     print "llamo al hack.pleasePrint"  
     hack.pleasePrint (self, reportNo, report, [ 'id='+str(ownDocumentBlock.idEntry) ],str(ownPosDocumentBlock.documentPrintCommand))  
     callTrigger('rollbackTrigger')  
 </trigger>  
   
   
  <trigger name="makeDespatchNote" type="NAMED">  
     import hack  
       
     print "entro al trigger"  
     if str(totalBlock.printDespatchNote) == "1":  
         # defino la funcion de callback  
         def invoiceForDespatchNote (despatchNoteId,despatchNoteNumber):  
             print "id",despatchNoteId,"number",despatchNoteNumber  
             ownDocumentBlock.relatedToEntry =  str(despatchNoteNumber).strip().rjust(8).replace(' ','0')  
             #solo para que no ensucie el update  
             if str(ownDocumentBlock.dueDateEntry) == "":  
                 ownDocumentBlock.dueDateEntry = None  
             documentRelationBlock.despatchEntry = str(despatchNoteId)  
             documentRelationBlock.invoiceEntry = str(ownDocumentBlock.idEntry)  
             documentRelationBlock.relationTypeEntry = str(<neb:Inline>'"'.PAPO::invoiceOfDespatchNote.'"'</neb:Inline>)  
             from gnue.common.GDataObjects import ConnectionError as DBError  
             try:  
                 print "largo el post changes"  
                 documentRelationBlock.postChanges()  
                 ownDocumentBlock.postChanges()  
                 commitConnection()  
             except DBError, err:  
                  genericBox("Hay problemas para grabar el numero de remito\n"+str(err),['Aceptar'])  
                  rollbackConnection()  
             callTrigger('invoiceForDespatchNoteTrigger')  
         # fin de definicion      
         print "llamo al otro form"  
         runForm ('despatchNote.gfd', {'invoiceid':str(ownDocumentBlock.idEntry),'invdocblock':ownDocumentBlock,'invitemblock':ownItemBlock ,'callback': invoiceForDespatchNote })  
     else:  
         print "no llamo a despatch note"  
   </trigger>  
   
   
   
   <!--=== ah, and here comes the dinner.... er, form! ===-->  
   <page name="Factura a Clientes">  
     <box height="9" label="Factura de Productos a Clientes"  
       name="invoiceHeaderBox" width="105" x="0" y="0">  
     <!--     Estos bloques son para la gestion del pago de la factura -->  
     
   
   
     <!-- Actualiza los datos del cliente -->  
     <trigger type="NAMED" name="bringClientDataTrigger"><![CDATA[  
   
     rs = clientDataSource.createResultSet({'_entity_data.id':str(ownDocumentBlock.clientRecipientBox.clientEntry)})  
     if rs.firstRecord():  
         ownDocumentBlock.clientRecipientBox.currentClientEntry = rs.current.getField('_entity_data._table')  
         #tmpValuesDataSource.taxSourceCode = rs.current.getField('_tax_data.graft')  
         tmpValuesDataSource.alienIVACond = rs.current.getField('_tax_profile_data._table')  
   
     if str(ownDocumentBlock.clientRecipientBox.currentClientEntry):  
         # Actualiza el puntaje  
         ownDocumentBlock.clientRecipientBox.scoreEntry = str(ownDocumentBlock.clientRecipientBox.clientEntry)  
         # Actualiza el limite de credito  
         ownDocumentBlock.clientRecipientBox.creditLimit1Entry = str(ownDocumentBlock.clientRecipientBox.clientEntry)  
         # Actualiza la Lista de precios asignada al cliente  
         ownDocumentBlock.clientRecipientBox.priceTypeEntry = str(ownDocumentBlock.clientRecipientBox.clientEntry)  
         # Aca si existe un balance, calcula la deuda desde ese balance en adelante sino  
         # calcula la deuda desde el primer documento vinculado al cliente actual  
         creditLimit1Block.clear()  
         creditLimit1Block.initQuery()  
         creditLimit1Block.entityEntry = str(ownDocumentBlock.clientRecipientBox.currentClientEntry)  
         creditLimit1Block.processQuery()  
         tmpValuesDataSource.creditLimitAmount = str(creditLimit1Block.creditLimitAmountEntry)  
   
         import gnue.common.GConditions as GConditions  
         import hack  
   
         condProductInvoice = GConditions.GCondition()  
         condCreditNote = GConditions.GCondition()  
         #condServiceInvoice = GConditions.GCondition()  
         condPay = GConditions.GCondition()  
   
         balance = 0  
         if str(creditLimit1Block.balanceEntry):  
             tmpAnd = GConditions.GCand(condProductInvoice)  
             gt = GConditions.GCgt(tmpAnd)  
             GConditions.GCField(gt,"own_document.date")  
             GConditions.GCConst(gt,str(creditLimit1Block.timeStampEntry))  
             eq = GConditions.GCeq(tmpAnd)  
             GConditions.GCField(eq,"_entity_data._table")  
             GConditions.GCConst(eq,str(ownDocumentBlock.clientRecipientBox.currentClientEntry))  
             tmpAnd = GConditions.GCand(condPay)  
             gt = GConditions.GCgt(tmpAnd)  
             GConditions.GCField(gt,"own_document.date")  
             GConditions.GCConst(gt,str(creditLimit1Block.timeStampEntry))  
             eq = GConditions.GCeq(tmpAnd)  
             GConditions.GCField(eq,"_entity_data._table")  
             GConditions.GCConst(eq,str(ownDocumentBlock.clientRecipientBox.currentClientEntry))  
             balance = hack.a2f(creditLimit1Block.balance,2)  
         else:  
             eq = GConditions.GCeq(condProductInvoice)  
             GConditions.GCField(eq,"_entity_data._table")  
             GConditions.GCConst(eq,str(ownDocumentBlock.clientRecipientBox.currentClientEntry))  
             eq = GConditions.GCeq(condCreditNote)  
             GConditions.GCField(eq,"_entity_data._table")  
             GConditions.GCConst(eq,str(ownDocumentBlock.clientRecipientBox.currentClientEntry))  
             eq = GConditions.GCeq(condPay)  
             GConditions.GCField(eq,"_entity_data._table")  
             GConditions.GCConst(eq,str(ownDocumentBlock.clientRecipientBox.currentClientEntry))  
   
         # Calculo del total facturado  
         ## Factura de productos  
         productInvoiceResultSet = productInvoiceTotalDataSource.createResultSet(condProductInvoice)  
         more = productInvoiceResultSet.firstRecord()  
         spentTotal = 0  
   
         while more:  
             currOwnDoc =   productInvoiceResultSet.current.getField("own_document.id")  
             invoiceTotal = hack.a2f(productInvoiceResultSet.current.getField("own_document.net_total"),4)+\  
                            hack.a2f(productInvoiceResultSet.current.getField("own_document.tax_total"),4)  
             spentTotal += invoiceTotal  
             more = productInvoiceResultSet.nextRecord()  
               
             
         # Calculo del total acreditado  
         productCreditNoteResultSet = productCreditNoteTotalDataSource.createResultSet(condCreditNote)  
         more = productCreditNoteResultSet.firstRecord()  
         creditTotal = 0  
   
         while more:  
             currOwnDoc = productCreditNoteResultSet.current.getField("own_document.id")  
             creditNoteTotal = hack.a2f(productCreditNoteResultSet.current.getField("own_document.net_total"),4)+\  
                               hack.a2f(productCreditNoteResultSet.current.getField("own_document.tax_total"),4)  
   
             creditTotal += creditNoteTotal  
             more = productCreditNoteResultSet.nextRecord()  
   
   
         # Calculo del total cobrado  
         paidResultSet = paidTotalDataSource.createResultSet(condPay)  
   
         more = paidResultSet.firstRecord()  
         import hack  
         payTotal = 0  
   
         while more:  
             payTotal += hack.a2f(paidResultSet.current.getField("own_document_proceeding.amount"),4)  
             more = paidResultSet.nextRecord()  
   
         #print "invoiceTotal ", invoiceTotal  
         #print "balance ", balance  
         #print "payTotal ", payTotal  
         #print "creditTotal ", creditTotal  
         # Calculo del total adeudado  
         deudaTotal = round(spentTotal - payTotal - creditTotal - balance,4)  
         ownDocumentBlock.clientRecipientBox.deudaEntry = deudaTotal  
   
         # ******** FALTA GRABAR EL BALANCE **************  
   
         # Obtiene el id de la lista de precios para poder buscar y lo coloca  
         # en una variable temporaria colgada del tmpValuesDataSource (un invento que parece que sirve no se si es prolijo)  
         clientResultSet = clientDataSource.createResultSet({"_entity_data._table": \  
                                                             str(ownDocumentBlock.clientRecipientBox.currentClientEntry)})  
         clientResultSet.firstRecord()  
         tmpValuesDataSource.priceTypeId = clientResultSet.current.getField("_price_type_data._table")  
         # Calcula el tipo de factura qeu corresponde en funcion de la condicion ante el IVA de la empresa y la del cliente  
         clientIvaTaxProfle = int(str(tmpValuesDataSource.alienIVACond))  
         providerIvaTaxProfile = int(str(tmpValuesDataSource.ownIVACond))  
         ownDocumentBlock.invoiceTypeEntry = hack.calcInvoiceType(clientIvaTaxProfle, providerIvaTaxProfile)  
         callTrigger('invoiceTypeValidation')  
           
         #cargo las formulas de calculo de impuestos  
                   
         #tmpValuesDataSource.taxSourceCode = rs.current.getField('_tax_data.graft')  
         callTrigger('searchTaxFormula')  
   ]]></trigger>  
   
    <neb:Sub neb:src="taxFormula.nebc" entityToId="ownDocumentBlock.clientRecipientBox.currentClientEntry" entityFromId="tmpValuesDataSource.ownOrganizationId" searchTaxFormula="searchTaxFormula"/>  
     <!-- Bloque para la búsqueda de clientes -->  
     <block name="clientResultBlock" datasource="clientSearchDataSource">  
     <entry name="idEntry" field="_entity_data.id" hidden="" x="1" y="1" width="12"/>  
 <!--         <entry name="uidTypeEntry" field="_entity_uid_data.entity_uid_type" hidden="" x="1" y="1" width="12"/>             -->  
         <entry name="uidEntry" field="_entity_uid_data.uid" hidden="" x="1" y="1" width="12"/>  
         <entry name="nameEntry" field="_entity_data.name" hidden="" x="1" y="1" width="20"/>  
     </block>  
     <trigger name="clientSearchTrigger" type="NAMED"><![CDATA[  
       tmpValuesDataSource.priceTypeId = None  
   
       codeToSearch = str(ownDocumentBlock.clientRecipientBox.clientCodeEntry)  
       nameToSearch = str(ownDocumentBlock.clientRecipientBox.clientNameEntry)  
   
       callTrigger('rollbackTrigger')  
   
       ownDocumentBlock.clientRecipientBox.clientCodeEntry = codeToSearch  
       ownDocumentBlock.clientRecipientBox.clientNameEntry = nameToSearch  
   
       callTrigger('startWaitingModeTrigger')  
       clientResultBlock.initQuery()  
       if codeToSearch:  
         clientResultBlock.uidEntry = codeToSearch+"%"  
       if nameToSearch:  
         clientResultBlock.nameEntry = nameToSearch+"%"  
       clientResultBlock.processQuery()  
       callTrigger('endWaitingModeTrigger')  
       recordCount = clientResultBlock.getRecordCount()  
       if recordCount > 1:  
         def callback (returnValue):  
           global block  
           if returnValue >= 0:  
             clientResultBlock.jumpRecord(returnValue)  
             ownDocumentBlock.clientRecipientBox.clientCodeEntry = str(clientResultBlock.uidEntry)  
             ownDocumentBlock.clientRecipientBox.clientNameEntry = str(clientResultBlock.nameEntry)  
             ownDocumentBlock.clientRecipientBox.clientEntry = str(clientResultBlock.idEntry)  
             callTrigger('startWaitingModeTrigger')  
             callTrigger('bringClientDataTrigger')  
             callTrigger('endWaitingModeTrigger')  
   
         runForm ('clientSelect.gfd', {'data': clientResultBlock, 'callback': callback})  
       elif recordCount == 1:  
         clientResultBlock.jumpRecord(0)  
         ownDocumentBlock.clientRecipientBox.clientCodeEntry = str(clientResultBlock.uidEntry)  
         ownDocumentBlock.clientRecipientBox.clientNameEntry = str(clientResultBlock.nameEntry)  
         ownDocumentBlock.clientRecipientBox.clientEntry = str(clientResultBlock.idEntry)  
         callTrigger('startWaitingModeTrigger')  
         callTrigger('bringClientDataTrigger')  
         callTrigger('endWaitingModeTrigger')  
   
   ]]></trigger>  
   
     <!--     Fin de bloques destinados a la gestion del pago de la factura -->  
     <block datasource="ownDocumentDataSource" name="ownDocumentBlock" restrictInsert="">  
         <entry field="id" hidden="" name="idEntry" x="1" y="1"/>  
 <!--         <entry field="net_total" hidden="" name="netTotalEntry" x="1" y="1"/> -->  
 <!--         <entry field="tax_total" hidden="" name="taxTotalEntry" x="1" y="1"/> -->  
         <entry field="due_date" hidden="" name="dueDateEntry" x="1" y="1"/>  
         
         <label text="remitos corresp.:" x="1" y="7"/>  
         <entry field="related_to" name="relatedToEntry" x="18" y="7" width="60" />  
         <!-- cargo pos -->  
         <entry field="own_entity" hidden="" name="ownPosEntityIdEntry" x="1" y="1"/>  
         <!-- /cargo pos -->  
         <entry field="own_document_type" hidden="" name="typeEntry" x="1" y="1"/>  
         <box height="5" label="Datos del Cliente" name="clientRecipientBox" width="103" x="0" y="2">  
         <label name="clientLbl" text="Cliente" x="1" y="1" />  
         <entry x="1" y="1" width="30" name="currentClientEntry" hidden="" />  
         <entry x="1" y="2" field="recipient" name="clientEntry" width="30" hidden=""/>  
         <entry x="1" y="2" name="clientCodeEntry" width="20">  
           <options>  
             <option name="tip" value="Insertar el Código"/>  
           </options>  
         </entry>  
         <entry x="21" y="2" name="clientNameEntry" width="35">  
           <options>  
             <option name="tip" value="Insertar el nombre o descripción"/>  
           </options>  
         </entry>  
   
         <button name="clientSearchButton" trigger="clientSearchTrigger" label="Buscar" x="56" y="2" width="7" height="1"/>  
         <button name="clientCallFormButton" trigger="clientCallFormTrigger" label="..." width="4" height="1" x="64" y="2"/>  
   
         <label name="clientLbl" text="Lista de precios:" x="1" y="3" />  
   
         <entry x="19" y="3" field="recipient" name="priceTypeEntry" readonly=""  
            width="20" style="textlookup" foreign_key="clientDataSource._entity_data.id"  
            foreign_key_description="_price_type_data.name" />  
   
 <!--         <label name="scoreLbl" text="Puntaje" x="64" y="1" /> -->  
 <!--         <entry x="64" y="2" readonly="" field="recipient" name="scoreEntry" -->  
 <!--                width="10" style="textlookup" foreign_key="clientDataSource._entity_data.id" -->  
 <!--                foreign_key_description="_client_data.score"/> -->  
   
         <label name="nameMVType1Label" text="Límite de Cta. Cte." x="75" y="1"/>  
   
         <entry x="75" y="2" readonly="" field="recipient" name="creditLimit1Entry"  
                width="10" style="textlookup" foreign_key="tlCreditLimit1DataSource._entity_data.id"  
                foreign_key_description="_credit_limit_data.credit_limit"/>  
   
         <label name="deudaLbl" text="|   Deuda : " x="40" y="3"/>  
         <entry name="deudaEntry" style="label" x="52" y="3" width="12" typecast="number" displaymask="%0.2f"/>  
   
         </box>  
         <entry field="date" name="dateEntry" style="label" hidden="" typecast="date"  
           rows="9" width="24" x="7" y="7"/>  
         <entry field="number" name="numberEntry" style="label" hidden="" width="24" x="7" y="7"/>  
   
         <label name="invoiceTypeLbl" text="Tipo" x="23" y="1" />  
         <entry name="invoiceTypeEntry" width="2" x="28" y="1">  
           <trigger type="PRE-FOCUSOUT" src="invoiceTypeValidation"/>  
         </entry>  
       </block>  
   
       <!-- Fecha de la factura -->  
       <block name="tmpBlock" datasource="tmpValuesDataSource" transparentBlock="">  
         <label name="dateLbl" text="Fecha" x="1" y="1" />  
         <label name="dateLabel" text="Número de Factura:" x="32" y="1"/>  
         <entry name="tmpDateEntry" typecast="date"  
           width="14" x="7" y="1"/>  
       </block>  
        <neb:Sub neb:src="posDocument.nebc" documentType="ownDocumentBlock.typeEntry"  
         ownPosBlock="ownPosBlock" stockByInvoice="stockByInvoice"  
         ownPosEntityIdEntry="ownPosEntityIdEntry"  ownPosDocumentBlock="ownPosDocumentBlock"  
         documentNumberEntry="documentNumberEntry" documentNumberEntryX="55" documentNumberEntryY="1"  
         searchNextDocumentNumber="searchNextInvoiceNumber"  
         ownStorehouseBlock ="ownStorehouseBlock" ownStorehouseIdEntry="ownStorehouseIdEntry"  />  
       <neb:Sub neb:src="documentRelation.nebc" documentRelationBlock="documentRelationBlock" despatchEntry="despatchEntry" invoiceEntry="invoiceEntry" />  
   
     </box>  
   
     <!--     ******************************** -->  
     <!--     Busqueda del producto a facturar -->  
     <!--     ******************************** -->  
   
     <!--     Datasource que sirve para la búsqueda del producto  -->  
     <datasource database="papo" name="priceTypeDataSource" table="_price_type_data">  
     <condition>  
       <null>  
         <cfield name="_price_type_data._end_t"/>  
       </null>  
     </condition>  
     </datasource>  
     <!--     Bloque que sirve para la búsqueda del producto respetando lista de precios -->  
     <block name="priceTypeBlock" datasource="priceTypeDataSource" transparentBlock="">  
       <entry name="priceTypeParentId"  field="parent" x="1"  
         y="2" width="40"  hidden=""/>  
       <entry name="priceTypeId" field="_table"  x="40" y="2" width="10" hidden="" />  
     </block>  
     <!--     Datasource que sirve para almacenar el resultado de la búsqueda -->  
     <datasource database="papo" name="productResultDataSource"  
       table="_product_code_type_data, _product_code_data, _product_data, _product_tax_data, _price_data, _price_type_data,  
              _currency_type_data"  
       order_by = "_product_data.canonical_name, _price_type_data._table desc" >  
       <condition>  
       <and>  
           <null>  
            <cfield name="_product_code_type_data._end_t"/>  
           </null>  
           <null>  
             <cfield name="_product_code_data._end_t"/>  
           </null>  
           <null>  
            <cfield name="_product_data._end_t"/>  
           </null>  
           <null>  
            <cfield name="_product_tax_data._end_t"/>  
           </null>  
           <null>  
             <cfield name="_price_data._end_t"/>  
           </null>  
           <null>  
             <cfield name="_price_type_data._end_t"/>  
           </null>  
           <null>  
             <cfield name="_currency_type_data._end_t"/>  
           </null>  
           <eq>  
             <cfield name="_product_code_type_data._table"/>  
             <cfield name="_product_code_data.product_code_type"/>  
           </eq>  
           <eq>  
             <cfield name="_product_data._table"/>  
             <cfield name="_product_code_data.product"/>  
           </eq>  
           <eq>  
             <cfield name="_product_data._table"/>  
             <cfield name="_product_tax_data.product"/>  
           </eq>  
           <eq>  
             <cfield name="_product_tax_data.tax"/>  
             <cconst value="1"/> <!-- IVA -->  
           </eq>  
           <eq>  
             <cfield name="_product_data._table"/>  
             <cfield name="_price_data.product"/>  
           </eq>  
           <eq>  
             <cfield name="_price_type_data._table"/>  
             <cfield name="_price_data.price_type"/>  
           </eq>  
           <!--multicurrency-->  
           <eq>  
             <cfield name="_currency_type_data._table"/>  
             <cfield name="_price_data.currency_type"/>  
           </eq>  
           <!--/multicurrency-->  
           <not>  
              <cfield name="_price_data.excluded"/> <!-- Solo productos no excluidos -->  
           </not>  
           <cfield name="_product_data.salable"/> <!-- Solo productos vendibles -->  
         </and>  
       </condition>  
     </datasource>  
     <!--     Bloque que sirve para almacenar el resultado intermedio de la búsqueda -->  
     <block  name="tmpProdResultBlock" datasource="productResultDataSource" transparentBlock="">  
       <entry name="prodNameEntry" field="_product_data.canonical_name" x="1" y="1" width="15" rows="2" hidden=""/>  
       <entry name="prodIdEntry" field="_product_data._table" x="15" y="1" width="5" rows="2" hidden=""/>  
       <entry name="prodCodeEntry" field="_product_code_data.code" x="20" y="1" width="10" rows="2" hidden=""/>  
       <entry name="prodCodeTypeEntry" field="_product_code_data.product_code_type" x="30" y="1" width="5" rows="2" hidden=""/>  
       <entry name="prodPriceTypeEntry" field="_price_type_data.name" x="35 " y="1" width="10" rows="2" hidden=""/>  
       <entry name="prodPriceTypeIdEntry" field="_price_type_data._table" x="45" y="1" width="5" rows="2" hidden=""/>  
       <entry name="prodUnitPriceEntry" field="_price_data.unit_price" x="50" y="1" width="20" rows="2" hidden=""/>  
       <entry name="prodPriceEntry" field="_price_data.id" x="50" y="1" width="20" rows="2" hidden=""/>  
       <entry name="prodIVATaxEntry" field="_product_tax_data.amount" x="50" y="1" width="20" rows="2" hidden=""/>  
       <entry name="prodCurrencyRateEntry" field="_currency_type_data.rate" x="50" y="1" width="20" rows="2" hidden=""/>  
     </block>  
   
     <trigger name="prodDeleteTrigger" type="NAMED">  
       ownItemBlock.prodCodeSEntry = ""  
       ownItemBlock.prodNameSEntry = ""  
       ownItemBlock.qtyEntry = 0.00  
       ownItemBlock.unitPriceEntry = 0.00  
       ownItemBlock.priceEntry = "0"  
       #IVA  
       #ownItemBlock.taxAmountEntry = 0  
       ownItemBlock.ivaEntry = 0  
       ownItemBlock.discountEntry = 0.00  
       ownItemBlock.bonusEntry = 0.00  
       ownItemBlock.itemTotalEntry = 0.00  
   
       callTrigger('totalCalcTrigger')  
     </trigger>  
   
     <trigger name="prodSearchTrigger" type="NAMED">  
     #armado de la lista de recorrido del arbol  
     if tmpValuesDataSource.priceTypeId:  
       search_id = str(tmpValuesDataSource.priceTypeId)  
       priceListsChain=[]  
       while search_id != "" :  
           priceTypeBlock.initQuery()  
           priceTypeBlock.priceTypeId = search_id  
           priceTypeBlock.processQuery()  
           search_id = str(priceTypeBlock.priceTypeParentId)  
           priceListsChain.append("%s" % priceTypeBlock.priceTypeId)  
       tmpProdResultBlock.clear()  
       tmpProdResultBlock.initQuery()  
       tmpProdResultBlock.prodNameEntry = ("%s" % ownItemBlock.prodNameSEntry)+"%"  
       tmpProdResultBlock.prodCodeEntry = ("%s" % ownItemBlock.prodCodeSEntry)+"%"  
       tmpProdResultBlock.prodCodeTypeEntry = "1" # Ver como elegimos el código adecuado  
       tmpProdResultBlock.processQuery()  
       # cargar la parte visible de modificacion de precios  
       tmpProdResultBlock.firstRecord()  
       product_id_anterior = None  
       prodResultBlock.clear()  
       for index in range(tmpProdResultBlock.getRecordCount()):  
           product_id=("%s" %tmpProdResultBlock.prodIdEntry)  
           if product_id != product_id_anterior:  
               for pricetype in priceListsChain:  
                   if pricetype == ("%s" %tmpProdResultBlock.prodPriceTypeIdEntry):  
                       if len(str(prodResultBlock.prodNameEntry)):  
                           prodResultBlock.newRecord()  
                       prodResultBlock.prodNameEntry= ("%s" %tmpProdResultBlock.prodNameEntry)  
                       prodResultBlock.prodCodeEntry= ("%s" %tmpProdResultBlock.prodCodeEntry)  
                       prodResultBlock.prodPriceTypeEntry=  ("%s" %tmpProdResultBlock.prodPriceTypeEntry)  
                       prodResultBlock.prodUnitPriceEntry= ("%s" %tmpProdResultBlock.prodUnitPriceEntry)  
                       prodResultBlock.prodPriceEntry = ("%s" %tmpProdResultBlock.prodPriceEntry)  
                       prodResultBlock.prodPricePreviousEntry= ("%s" %tmpProdResultBlock.prodUnitPriceEntry)  
                       prodResultBlock.prodProductIdEntry= ("%s" %tmpProdResultBlock.prodIdEntry)  
                       prodResultBlock.prodPriceListIdEntry= ("%s" %tmpProdResultBlock.prodPriceTypeIdEntry)  
                       prodResultBlock.prodIVATaxEntry= ("%s" %tmpProdResultBlock.prodIVATaxEntry)  
                       prodResultBlock.prodCurrencyRateEntry= ("%s" %tmpProdResultBlock.prodCurrencyRateEntry)  
                       product_id_anterior=product_id  
                       break  
           tmpProdResultBlock.nextRecord()  
       prodResultBlock.jumpRecord(0)  
       recordCount = prodResultBlock.getRecordCount()  
       if recordCount > 1:  
         def callback (returnValue):  
           global block  
           if returnValue >= 0:  
             prodResultBlock.jumpRecord(returnValue)  
             callTrigger('prodInsertTrigger')  
   
         runForm ('productSelect.gfd', {'data': prodResultBlock, 'callback': callback})  
       elif recordCount == 1:  
         prodResultBlock.jumpRecord(0)  
         if not prodResultBlock.isEmpty():  
           callTrigger('prodInsertTrigger')  
     else:  
       genericBox("Debe elegir un cliente para poder cargar productos",['Aceptar'])  
   </trigger>  
   
   <!--   En este bloque se almacena el reultado final/real de la búsqueda para seleccion el correcto -->  
   <block name="prodResultBlock" datasource="prodResultDataSource" restrictInsert="" transparentBlock="">  
     <entry name="prodCodeEntry" width="10" x="37" y="10" rows="2" hidden=""/>  
     <entry name="prodNameEntry" width="22" x="47" y="10" rows="2" hidden=""/>  
     <entry name="prodPriceTypeEntry"  x="1 " y="1" width="10" rows="8" hidden=""/>  
     <entry name="prodUnitPriceEntry"  x="1" y="1" width="10" rows="8" hidden=""/>  
     <entry name="prodPriceEntry" x="1" y="1" width="20" rows="2" hidden=""/>  
     <entry name="prodPricePreviousEntry"  x="1" y="1" width="10" rows="8" hidden=""/>  
     <entry name="prodProductIdEntry"  x="1" y="1" width="5" rows="8" hidden=""/>  
     <entry name="prodPriceListIdEntry"  x="1" y="1" width="5" rows="8" hidden=""/>  
     <entry name="prodIVATaxEntry"  x="1" y="1" width="5" rows="8" hidden=""/>  
     <entry name="prodCurrencyRateEntry"  x="1" y="1" width="10" rows="8" hidden=""/>  
   </block>  
   <!--   Insertar el producto seleccionado -->  
   <trigger name="prodInsertTrigger" type="NAMED">  
     import hack  
   
     ownItemBlock.prodCodeSEntry = str(prodResultBlock.prodCodeEntry)  
     ownItemBlock.prodNameSEntry = str(prodResultBlock.prodNameEntry)  
     ownItemBlock.priceEntry = str(prodResultBlock.prodPriceEntry)  
   
     prodResultBlock.prodUnitPriceEntry = round(hack.a2f(prodResultBlock.prodUnitPriceEntry,4) * \  
                                          hack.a2f(prodResultBlock.prodCurrencyRateEntry,4),4)  
     lItemPrice = round(hack.a2f(prodResultBlock.prodUnitPriceEntry,4)*hack.a2f(ownItemBlock.qtyEntry,4),2)  
     #ownItemBlock.taxAmountEntry = round((hack.a2f(prodResultBlock.prodIVATaxEntry,4)/100) * lItemPrice,4)  
     ownItemBlock.ivaEntry = hack.a2f(prodResultBlock.prodIVATaxEntry,2)  
     ownItemBlock.unitPriceAuxEntry = str(prodResultBlock.prodUnitPriceEntry)  
     callTrigger('setUnitPriceTrigger')  
     callTrigger('totalCalcTrigger')  
   </trigger>  
   <!--     ****** Fin búsqueda ************ -->  
   <block datasource="ownDocumentDataSource" name="ownDocAuxBlock">  
         <entry x="62" y="10" name="withIvaEntry" style="checkbox" width="1" default="0">  
           <trigger name="withIvaEntryPreFocusout" type="PRE-FOCUSOUT" src="changePriceWithIvaTrigger" />  
         </entry>  
   </block>  
   <block datasource="ownItemDataSource" name="ownItemBlock">  
       <entry name="ivaRNIAmountEntry" x="1" y ="1" hidden=""/>  
       <entry name="ivaAmountEntry" x="1" y ="1" hidden=""/>  
       <entry name="ownItemId" x="1" y ="1" hidden="" field="own_item.id"/>  
       <label text="Productos a facturar" x="1" y="9"/>  
       <label text="Código" x="1" y="10"/>  
       <entry name="prodCodeSEntry" width="14" x="1" y="11" rows="9">  
         <options>  
           <option name="tip" value="Insertar el código"/>  
         </options>  
     </entry>  
     <label text="Nombre" x="15" y="10"/>  
     <entry name="prodNameSEntry" width="20" x="15" y="11" rows="9">  
         <options>  
           <option name="tip" value="Insertar el nombre o descripción del producto"/>  
         </options>  
     </entry>  
     <button name="prodSearchButton" trigger="prodSearchTrigger" label="Buscar" width="7" height="9" x="35" y="11"/>  
     <button name="prodCallFormButton" trigger="prodCallFormTrigger" label=".." width="3" height="9" x="42" y="11"/>  
   
     <entry field="own_item.own_document" name="ownDocumentEntry" hidden="" x="1" y="1"/>  
   
     <label name="qtyLbl" text="Cantidad" x="45" y="10"/>  
     <entry field="own_product_item.qty" name="qtyEntry" rows="9" typecast="number"  
         displaymask="%0.4f" width="11" x="45" y="11">  
     <trigger name="qtyEntryPreFocusout" type="PRE-FOCUSOUT" src="totalCalcTrigger" />  
     </entry>  
   
         <label name="priceLbl" text="Precio" x="56" y="9"/>  
         <label name="priceLbl" text="c/iva" x="56" y="10"/>  
         <entry x="56" y="11" name="unitPriceAuxEntry" width="10" rows="9"  
         typecast="number" displaymask="%0.4f">  
           <trigger name="setUnitPriceAuxEntryPreFocusout" type="PRE-FOCUSOUT" src="setUnitPriceTrigger" />  
           <trigger name="unitPriceEntryPreFocusout" type="PRE-FOCUSOUT" src="totalCalcTrigger" />  
         </entry>  
         <entry x="56" y="11" name="unitPriceEntry" field="own_product_item.unit_price" width="10" rows="9"  
         typecast="number" displaymask="%0.4f" hidden=""/>  
         <entry x="1" y="14" readonly="" field="own_product_item.price" name="priceEntry" width="10" rows="5" hidden=""/>  
         <label name="ivaLbl" text="IVA" x="66" y="10"/>  
         <entry name="ivaEntry" displaymask="%0.0f"  
           rows="9" width="3" x="66" y="11" default="0">  
           <trigger name="setUnitPriceAuxEntryPreFocusout" type="PRE-FOCUSOUT" src="setUnitPriceTrigger" />  
           <trigger name="ivaEntryPreFocusout" type="PRE-FOCUSOUT" src="totalCalcTrigger" />  
         </entry>  
         <label name="discountLbl" text="Dto." x="70" y="10"/>  
         <entry field="own_item.discount" name="discountEntry" default="0.00" typecast="number" displaymask="%0.2f"  
           rows="9" width="6" x="69" y="11">  
           <trigger name="discountEntryPreFocusout" type="PRE-FOCUSOUT" src="totalCalcTrigger" />  
          </entry>  
         <entry field="own_item.bonus" name="bonusEntry" style="label" default="0.00" typecast="number" displaymask="%0.2f"  
           rows="9" width="10" x="79" y="11" hidden=""/>  
         <label name="itemNetolLbl" text="Neto" x="76" y="10"/>  
         <entry name="itemNetoEntry" style="label" default="0.00" typecast="number" displaymask="%0.2f"  
           rows="9" width="10" x="76" y="11"/>  
         <label name="itemTotalLbl" text="Total" x="85" y="10"/>  
         <entry name="itemTotalEntry" style="label" default="0.00" typecast="number" displaymask="%0.2f"  
           rows="9" width="10" x="85" y="11">  
         </entry>  
         <button name="prodDeleteButton" trigger="prodDeleteTrigger" label="Borrar" width="7" height="9" x="95" y="11"/>  
         <scrollbar page="5" x="103" y="11" width="1" height="10"/>  
        </block>  
   
     <neb:Sub neb:src="ownItemTax.nebc"/>  
   
     
     <!--     Datasource que sirve para almacenar el resultado de la búsqueda -->  
     <block datasource="ownDocumentDataSource" name="totalBlock" restrictInsert="">  
       <label text="Neto " x="55" y="21"/>  
       <entry name="netoEntry" field="own_document.net_total" x="55" y="22" width="12" typecast="number" displaymask="%0.2f"  
         default="0.00">  
         <trigger type="PRE-FOCUSOUT" src="recalcTotalTrigger"/>  
       </entry>  
       <label text="IVA " x="66" y="21"/>  
       <entry name="ivaEntry" field="own_document.tax_total" x="66" y="22" width="12" typecast="number" displaymask="%0.2f"  
         default="0.00">  
         <trigger type="PRE-FOCUSOUT" src="recalcTotalTrigger"/>  
       </entry>  
       <label text="Total " x="82" y="21"/>  
       <entry name="totalEntry" style="label" readonly="" x="82" y="22" width="12" typecast="number" displaymask="%0.2f" default="0.00"/>  
       <label text="emitir remito" x="38" y="22" />  
       <entry name="printDespatchNote"  x="51" y="22" style="checkbox">  
         <trigger type="PRE-FOCUSOUT" src="alertOfDespatchNoteTrigger"/>  
       </entry>  
     </block>  
     <neb:Sub neb:src="setStock.nebc"   ownDocumentId="ownDocumentBlock.idEntry" storehouseEntityId="ownStorehouseBlock.ownStorehouseIdEntry"  
       stockAddTrigger="stockAddTrigger" stockSubstractTrigger="stockSubstractTrigger"/>  
       <block datasource="creditLimit1DataSource" name="creditLimit1Block">  
         <entry name="entityEntry" field="_credit_limit_data.entity" hidden="" x="11" y="109" width="10"/>  
         <entry name="movementTypeEntry" field="_credit_limit_data.movement_type" hidden="" x="1" y="109" width="10"/>  
         <entry name="creditLimitAmountEntry" field="_credit_limit_data.credit_limit" hidden="" x="1" y="109" width="10"/>  
         <entry name="balanceEntry" field="_credit_limit_data.balance" hidden="" x="22" y="109" width="10"/>  
         <entry name="timeStampEntry" field="_credit_limit_data.time_stamp" hidden="" x="33" y="109" width="10"/>  
       
       <!--     Estos 2 botones estaba antes en el box cobro de facura  -->  
         <button name="printButton" label="Doc. Terminado" trigger="invoiceOkTrigger"  
           x="1" y="22" width="16" height="1"/>  
         <button x="18" y="22" trigger="rollbackTrigger" width="18" label="Cancelar"  
           name="rollbackBtn" height="1"/>  
         <!--     Estos 2 botones estaba antes en el box cobro de facura  -->  
   
       </block>  
   
     <block name="ownOrganizationBlock" datasource="ownOrganizationDataSource">  
       <entry name="ownOrganizationIdEntry" field="_entity_data._table" hidden="" x="1" y="1"/>  
       <entry name="condIVAEntry" field="_tax_profile_data._table" hidden="" x="1" y="1" width="10"/>  
     </block>  
   </page>  
 <!-- Llamo al componente de pagos -->  
   <neb:Sub neb:src="ownDocumentPay.nebc" />  
   
18  </form>  </form>

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.40

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26