From efd24e5922b1eb75b2b75b8795fb7b8188b2dc34 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sat, 29 Oct 2016 07:45:24 +0200 Subject: [PATCH 1/3] Work on supplier credit note --- htdocs/compta/facture.php | 70 +++++++++++++++++------------------ htdocs/fourn/facture/card.php | 50 +++++++++++++------------ 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 2f4f887f652..3ee875b5d93 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2933,17 +2933,17 @@ else if ($id > 0 || ! empty($ref)) } } $morehtmlref.=''; - + $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status - + dol_banner_tab($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref, '', 0, '', $morehtmlright); - + print '
'; print '
'; print '
'; - + print ''; - + // Type print '
' . $langs->trans('Type') . ''; print $object->getLibType(); @@ -3303,7 +3303,7 @@ else if ($id > 0 || ! empty($ref)) include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print '
'; - + print '
'; print '
'; print '
'; @@ -3328,15 +3328,15 @@ else if ($id > 0 || ! empty($ref)) print '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; print ''; } - + // Amount - print '' . $langs->trans('AmountHT') . ''; + print '' . $langs->trans('AmountHT') . ''; print '' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . ''; - + // Vat print '' . $langs->trans('AmountVAT') . '' . price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency) . ''; print ''; - + // Amount Local Taxes if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) // Localtax1 { @@ -3348,7 +3348,7 @@ else if ($id > 0 || ! empty($ref)) print '' . $langs->transcountry("AmountLT2", $mysoc->country_code) . ''; print '' . price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency) . ''; } - + // Revenue stamp if ($selleruserevenustamp) // Test company use revenue stamp { @@ -3375,14 +3375,14 @@ else if ($id > 0 || ! empty($ref)) } print ''; } - + // Total with tax print '' . $langs->trans('AmountTTC') . '' . price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency) . ''; - + print ''; - + // List of payments - + $sign = 1; if ($object->type == Facture::TYPE_CREDIT_NOTE) $sign = - 1; $nbrows = 8; @@ -3491,9 +3491,9 @@ else if ($id > 0 || ! empty($ref)) if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0) print ''; } - + print ''; - + // List of payments already done print ''; print ''; @@ -3505,9 +3505,9 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; - + $var = true; - + // Payments already done (from payment on this invoice) $sql = 'SELECT p.datep as dp, p.ref, p.num_paiement, p.rowid, p.fk_bank,'; $sql .= ' c.code as payment_code, c.libelle as payment_label,'; @@ -3518,12 +3518,12 @@ else if ($id > 0 || ! empty($ref)) $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid'; $sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid'; $sql .= ' ORDER BY p.datep, p.tms'; - + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; - + // if ($object->type != 2) // { if ($num > 0) { @@ -3563,7 +3563,7 @@ else if ($id > 0 || ! empty($ref)) } else { dol_print_error($db); } - + if ($object->type != Facture::TYPE_CREDIT_NOTE) { // Total already paid print ''; - + $resteapayeraffiche = $resteapayer; $cssforamountpaymentcomplete = 'amountpaymentcomplete'; - + // Loop on each credit note or deposit amount applied $creditnoteamount = 0; $depositamount = 0; @@ -3611,7 +3611,7 @@ else if ($id > 0 || ! empty($ref)) } else { dol_print_error($db); } - + // Paye partiellement 'escompte' if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'discount_vat') { print ''; @@ -3667,10 +3667,10 @@ else if ($id > 0 || ! empty($ref)) print ''; - + // Billed print ''; - + // Remainder to pay back print ''; print ''; print ''; - + // Sold credit note // print ''; // print ''; } - + print '
' . ($object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')) . '' . $langs->trans('Amount') . ' 
'; @@ -3572,10 +3572,10 @@ else if ($id > 0 || ! empty($ref)) else print $langs->trans('AlreadyPaid'); print ' : 0)?' class="amountalreadypaid"':'').'>' . price($totalpaye) . ' 
'; @@ -3647,7 +3647,7 @@ else if ($id > 0 || ! empty($ref)) $resteapayeraffiche = 0; $cssforamountpaymentcomplete = ''; } - + // Billed print '
' . $langs->trans("Billed") . ' :' . price($object->total_ttc) . ' 
'; print $langs->trans('AlreadyPaidBack'); print ' :' . price($sign * $totalpaye) . ' 
' . $langs->trans("Billed") . ' :' . price($sign * $object->total_ttc) . ' 
'; if ($resteapayeraffiche <= 0) @@ -3680,27 +3680,26 @@ else if ($id > 0 || ! empty($ref)) print ' :' . price($sign * $resteapayeraffiche) . ' 
'.$langs->trans('TotalTTC').' :'.price($sign * // $object->total_ttc).' 
'; - + // Margin Infos if (! empty($conf->margin->enabled)) { $formmargin->displayMarginInfos($object); } - print '
'; print '
'; print '
'; - + print '

'; - + if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { $blocname = 'contacts'; $title = $langs->trans('ContactsAddresses'); @@ -3811,8 +3810,7 @@ else if ($id > 0 || ! empty($ref)) print '
'; $parameters = array(); - $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been - // modified by hook + $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { // Editer une facture deja validee, sans paiement effectue et pas exporte en compta if ($object->statut == 1) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index bd7d1317957..1fbbe41978b 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -8,7 +8,7 @@ * Copyright (C) 2013-2015 Philippe Grand * Copyright (C) 2013 Florian Henry * Copyright (C) 2014 Marcos García - * Copyright (C) 2016 Alexandre Spangaro + * Copyright (C) 2016 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -2249,9 +2249,9 @@ else print '
'; print '
'; print '
'; - + print ''; - + // Amount print ''; print ''; - + // Amount Local Taxes //TODO: Place into a function to control showing by country or study better option if ($societe->localtax1_assuj=="1") //Localtax1 @@ -2281,7 +2281,7 @@ else print ''; } print ''; - + if (!empty($conf->multicurrency->enabled)) { // Multicurrency Amount HT @@ -2298,22 +2298,26 @@ else print ''; print ''; print ''; - } - + } + print '
'.$langs->trans('AmountHT').''.price($object->total_ht,1,$langs,0,-1,-1,$conf->currency).'
'.$langs->trans('AmountVAT').''.price($object->total_tva,1,$langs,0,-1,-1,$conf->currency).'
        '; @@ -2265,7 +2265,7 @@ else $s.=''.$langs->trans("Mode2").''; print $form->textwithtooltip($s, $langs->trans("CalculationRuleDesc",$calculationrulenum).'
'.$langs->trans("CalculationRuleDescSupplier"), 2, 1, img_picto('','help')); print '
'.$langs->trans('AmountTTC').''.price($object->total_ttc,1,$langs,0,-1,-1,$conf->currency).'
' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '
'; - + /* * List of payments */ - $nbrows=9; $nbcols=3; + $sign = 1; + if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) $sign = - 1; + + $nbrows=9; $nbcols=3; if (! empty($conf->projet->enabled)) $nbrows++; if (! empty($conf->banque->enabled)) { $nbrows++; $nbcols++; } if (! empty($conf->incoterm->enabled)) $nbrows++; - + if (! empty($conf->multicurrency->enabled)) $nbrows += 5; + // Local taxes if ($societe->localtax1_assuj=="1") $nbrows++; if ($societe->localtax2_assuj=="1") $nbrows++; - + $sql = 'SELECT p.datep as dp, p.ref, p.num_paiement, p.rowid, p.fk_bank,'; $sql.= ' c.id as paiement_type,'; $sql.= ' pf.amount,'; @@ -2325,7 +2329,7 @@ else $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid'; $sql.= ' WHERE pf.fk_facturefourn = '.$object->id; $sql.= ' ORDER BY p.datep, p.tms'; - + $result = $db->query($sql); if ($result) { @@ -2333,14 +2337,14 @@ else $i = 0; $totalpaye = 0; print ''; print ''; - print ''; + print ''; print ''; print ''; if (! empty($conf->banque->enabled)) print ''; print ''; print ''; print ''; - + $var=false; if ($num > 0) { @@ -2369,7 +2373,7 @@ else if ($objp->baid > 0) print $bankaccountstatic->getNomUrl(1,'transactions'); print ''; } - print ''; + print ''; print ''; + + $resteapayeraffiche = $resteapayer; + $cssforamountpaymentcomplete = 'amountpaymentcomplete'; + + // Loop on each credit note or deposit amount applied + $creditnoteamount = 0; + $depositamount = 0; + $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; + $sql .= " re.description, re.fk_facture_source"; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re"; + $sql .= " WHERE fk_facture = " . $object->id; + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + $invoice = new FactureFournisseur($db); + while ($i < $num) { + $obj = $db->fetch_object($resql); + $invoice->fetch($obj->fk_facture_source); + print ''; + print ''; + print ''; + $i ++; + if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) + $creditnoteamount += $obj->amount_ttc; + if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) + $depositamount += $obj->amount_ttc; + } + } else { + dol_print_error($db); + } + + // Paye partiellement 'escompte' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'discount_vat') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = ''; + } + // Paye partiellement ou Abandon 'badsupplier' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'badsupplier') { + print ''; + // $resteapayeraffiche=0; + $cssforamountpaymentcomplete = ''; + } + // Paye partiellement ou Abandon 'product_returned' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'product_returned') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = ''; + } + // Paye partiellement ou Abandon 'abandon' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'abandon') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = ''; + } + + // Billed + print ''; + + // Remainder to pay + print ''; + print ''; + print ''; + } + else // Credit note + { + // Total already paid back + print ''; + + // Billed + print ''; + + // Remainder to pay back + print ''; + print ''; + print ''; + + // Sold credit note + // print ''; + // print ''; + } + + print '
'.$langs->trans('Payments').'' . ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')) . ''.$langs->trans('Date').''.$langs->trans('Type').''.$langs->trans('BankAccount').''.$langs->trans('Amount').' 
'.price($objp->amount).'' . price($sign * $objp->amount) . ''; if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->societe_id == 0) { @@ -2405,7 +2409,6 @@ else { dol_print_error($db); } - print ''; print ''; @@ -2435,13 +2438,12 @@ else //$result = $object->getLinesArray(); - print '
- - - - - - '; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; if (! empty($conf->use_javascript_ajax) && $object->statut == FactureFournisseur::STATUS_DRAFT) { include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; @@ -2449,7 +2451,7 @@ else print ''; - global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax; + global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax; $forceall=1; $senderissupplier=1; $dateSelector=0; $inputalsopricewithtax=1; // Show object lines From 7be49e47b81dc5e75393b8349f6929458ec1610e Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Tue, 1 Nov 2016 17:09:51 +0100 Subject: [PATCH 2/3] indenting and little refactoring --- .../expedition/doc/pdf_rouget.modules.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php index 7420e347482..ece59790fc3 100644 --- a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php @@ -790,7 +790,7 @@ class pdf_rouget extends ModelePdfExpedition // Show Draft Watermark if($object->statut==0 && (! empty($conf->global->SHIPPING_DRAFT_WATERMARK)) ) { - pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SHIPPING_DRAFT_WATERMARK); + pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SHIPPING_DRAFT_WATERMARK); } //Prepare la suite @@ -861,11 +861,11 @@ class pdf_rouget extends ModelePdfExpedition $pdf->SetTextColor(0,0,60); $title=$outputlangs->transnoentities("SendingSheet"); $pdf->MultiCell($w, 4, $title, '', 'R'); - $posy+=1; $pdf->SetFont('','', $default_font_size + 1); - $posy+=4; + $posy+=5; + $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R'); @@ -873,10 +873,10 @@ class pdf_rouget extends ModelePdfExpedition // Date planned delivery if (! empty($object->date_delivery)) { - $posy+=4; - $pdf->SetXY($posx,$posy); - $pdf->SetTextColor(0,0,60); - $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery,"day",false,$outputlangs,true), '', 'R'); + $posy+=4; + $pdf->SetXY($posx,$posy); + $pdf->SetTextColor(0,0,60); + $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery,"day",false,$outputlangs,true), '', 'R'); } if (! empty($object->thirdparty->code_client)) @@ -889,11 +889,10 @@ class pdf_rouget extends ModelePdfExpedition $pdf->SetFont('','', $default_font_size + 3); - $Yoff=25; + $Yoff=25; - // Add list of linked orders - - $origin = $object->origin; + // Add list of linked orders + $origin = $object->origin; $origin_id = $object->origin_id; // TODO move to external function From de8ed22448933b0211fb01abc00da8ddd834df7e Mon Sep 17 00:00:00 2001 From: aspangaro Date: Wed, 2 Nov 2016 07:13:17 +0100 Subject: [PATCH 3/3] Work on supplier credit/deposit/replacement invoice --- .../fourn/class/fournisseur.facture.class.php | 2 +- htdocs/fourn/facture/card.php | 139 +++++++++++++++++- 2 files changed, 132 insertions(+), 9 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 9b3de478cc9..5241105a90e 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -10,7 +10,7 @@ * Copyright (C) 2014-2016 Marcos García * Copyright (C) 2015 Bahfir Abbes * Copyright (C) 2015 Ferran Marcet - * Copyright (C) 2016 Alexandre Spangaro + * Copyright (C) 2016 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 1fbbe41978b..e301c7aaa13 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -486,10 +486,10 @@ if (empty($reshook)) { // Reset fk_parent_line for no child products and special product if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) { - $fk_parent_line = 0; + $fk_parent_line = 0; } - $line->fk_facture = $object->id; + $line->fk_facture_fourn = $object->id; $line->fk_parent_line = $fk_parent_line; $line->subprice =-$line->subprice; // invert price for object @@ -2391,7 +2391,8 @@ else { print ''; } - + + /* if ($object->paye == 0) { print ''; @@ -2402,7 +2403,8 @@ else print ''; print ''; } - print '
'.$langs->trans("None").'
'.$langs->trans('AlreadyPaid').' :'.price($totalpaye).'
'.$langs->trans('RemainderToPay').' :'.price($resteapayer).'
'; + */ + $db->free($result); } else @@ -2410,6 +2412,131 @@ else dol_print_error($db); } + if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) { + // Total already paid + print '
'; + if ($object->type != FactureFournisseur::TYPE_DEPOSIT) + print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits'); + else + print $langs->trans('AlreadyPaid'); + print ' : 0)?' class="amountalreadypaid"':'').'>' . price($totalpaye) . ' 
'; + if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) + print $langs->trans("CreditNote") . ' '; + if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) + print $langs->trans("Deposit") . ' '; + print $invoice->getNomUrl(0); + print ' :' . price($obj->amount_ttc) . ''; + print 'rowid . '">' . img_delete() . ''; + print '
'; + print $form->textwithpicto($langs->trans("Discount") . ':', $langs->trans("HelpEscompte"), - 1); + print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
'; + print $form->textwithpicto($langs->trans("Abandoned") . ':', $langs->trans("HelpAbandonBadCustomer"), - 1); + print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
'; + print $form->textwithpicto($langs->trans("ProductReturned") . ':', $langs->trans("HelpAbandonProductReturned"), - 1); + print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
'; + $text = $langs->trans("HelpAbandonOther"); + if ($object->close_note) + $text .= '

' . $langs->trans("Reason") . ':' . $object->close_note; + print $form->textwithpicto($langs->trans("Abandoned") . ':', $text, - 1); + print '
' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
' . $langs->trans("Billed") . ' :' . price($object->total_ttc) . ' 
'; + if ($resteapayeraffiche >= 0) + print $langs->trans('RemainderToPay'); + else + print $langs->trans('ExcessReceived'); + print ' :' . price($resteapayeraffiche) . ' 
'; + print $langs->trans('AlreadyPaidBack'); + print ' :' . price($sign * $totalpaye) . ' 
' . $langs->trans("Billed") . ' :' . price($sign * $object->total_ttc) . ' 
'; + if ($resteapayeraffiche <= 0) + print $langs->trans('RemainderToPayBack'); + else + print $langs->trans('ExcessPaydBack'); + print ' :' . price($sign * $resteapayeraffiche) . ' 
'.$langs->trans('TotalTTC').' :'.price($sign * + // $object->total_ttc).' 
'; + print '
'; print '
'; print '
'; @@ -2435,9 +2562,6 @@ else /* * Lines */ - //$result = $object->getLinesArray(); - - print ''; print ''; print ''; @@ -2526,7 +2650,6 @@ else else print ''.$langs->trans('SendByMail').''; } - // Make payments if ($action != 'edit' && $object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->societe_id == 0) {