From ba56e679bde29499aaf16e96fb5e4c6e64229201 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 5 Nov 2012 17:21:05 +0100 Subject: [PATCH] Fix: Calculation of default date for payment term was not using function. --- htdocs/compta/facture.php | 118 ++++++++++++++++++++------------------ 1 file changed, 63 insertions(+), 55 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index d3faa909ac2..92ff891cca9 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -266,36 +266,46 @@ else if ($action == 'setmode' && $user->rights->facture->creer) else if ($action == 'setinvoicedate' && $user->rights->facture->creer) { $object->fetch($id); + $old_date_lim_reglement=$object->date_lim_reglement; $object->date=dol_mktime(12,0,0,$_POST['invoicedatemonth'],$_POST['invoicedateday'],$_POST['invoicedateyear']); + $new_date_lim_reglement=$object->calculate_date_lim_reglement(); + if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement=$new_date_lim_reglement; if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement=$object->date; $result=$object->update($user); if ($result < 0) dol_print_error($db,$object->error); } +else if ($action == 'setconditions' && $user->rights->facture->creer) +{ + $object->fetch($id); + $object->cond_reglement_code=0; // To clean property + $object->cond_reglement_id=0; // To clean property + $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); + if ($result < 0) dol_print_error($db,$object->error); + + $old_date_lim_reglement=$object->date_lim_reglement; + $new_date_lim_reglement=$object->calculate_date_lim_reglement(); + if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement=$new_date_lim_reglement; + if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement=$object->date; + $result=$object->update($user); + if ($result < 0) dol_print_error($db,$object->error); +} else if ($action == 'setpaymentterm' && $user->rights->facture->creer) { $object->fetch($id); $object->date_lim_reglement=dol_mktime(12,0,0,$_POST['paymenttermmonth'],$_POST['paymenttermday'],$_POST['paymenttermyear']); if ($object->date_lim_reglement < $object->date) { - $object->date_lim_reglement=$object->date; + $object->date_lim_reglement=$object->calculate_date_lim_reglement(); setEventMessage($langs->trans("DatePaymentTermCantBeLowerThanObjectDate"),'warnings'); } $result=$object->update($user); if ($result < 0) dol_print_error($db,$object->error); } -else if ($action == 'setconditions' && $user->rights->facture->creer) -{ - $object->fetch($id); - $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); - if ($result < 0) dol_print_error($db,$object->error); -} - else if ($action == 'setremisepercent' && $user->rights->facture->creer) { $object->fetch($id); $result = $object->set_remise($user, $_POST['remise_percent']); } - else if ($action == "setabsolutediscount" && $user->rights->facture->creer) { // POST[remise_id] ou POST[remise_id_for_payment] @@ -764,7 +774,7 @@ else if ($action == 'add' && $user->rights->facture->creer) if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } if ($element == 'contract') { $element = $subelement = 'contrat'; } if ($element == 'inter') { $element = $subelement = 'ficheinter'; } - if ($element == 'shipping') {$element = $subelement = 'expedition'; } + if ($element == 'shipping') { $element = $subelement = 'expedition'; } $object->origin = $_POST['origin']; $object->origin_id = $_POST['originid']; @@ -2823,14 +2833,40 @@ else if ($id > 0 || ! empty($ref)) print ''; - // Margin Infos - if (! empty($conf->margin->enabled)) { - print '
'; - $object->displayMarginInfos($object->statut > 0); - } + // Margin Infos + if (! empty($conf->margin->enabled)) + { + print '
'; + $object->displayMarginInfos($object->statut > 0); + } print ''; + // Conditions de reglement + print ''; + print ''; + if ($object->type != 2 && $action != 'editconditions' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; + print '
'; + print $langs->trans('PaymentConditionsShort'); + print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; + print ''; + if ($object->type != 2) + { + if ($action == 'editconditions') + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->cond_reglement_id,'cond_reglement_id'); + } + else + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->cond_reglement_id,'none'); + } + } + else + { + print ' '; + } + print ''; + // Date payment term print ''; print ''; - // Conditions de reglement - print ''; - - // Mode de reglement + // Payment mode print '
'; @@ -2857,32 +2893,7 @@ else if ($id > 0 || ! empty($ref)) } print '
'; - print ''; - if ($object->type != 2 && $action != 'editconditions' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; - print '
'; - print $langs->trans('PaymentConditionsShort'); - print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; - print '
'; - if ($object->type != 2) - { - if ($action == 'editconditions') - { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->cond_reglement_id,'cond_reglement_id'); - } - else - { - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id,$object->cond_reglement_id,'none'); - } - } - else - { - print ' '; - } - print '
'; print ''; print ''; - print ''; + print ''; // Amount Local Taxes - if ($mysoc->pays_code=='ES') + if ($mysoc->localtax1_assuj=="1") //Localtax1 RE { - if ($mysoc->localtax1_assuj=="1") //Localtax1 RE - { - print ''; - print ''; - print ''; - } - if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF - { - print ''; - print ''; - print ''; - } + print ''; + print ''; + print ''; + } + if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF + { + print ''; + print ''; + print ''; } print '';
'; print $langs->trans('PaymentMode'); @@ -2907,23 +2918,20 @@ else if ($id > 0 || ! empty($ref)) print '
'.$langs->trans('AmountVAT').''.price($object->total_tva).''.$langs->trans('Currency'.$conf->currency).'
'.$langs->transcountry("AmountLT1",$mysoc->pays_code).''.price($object->total_localtax1).''.$langs->trans("Currency".$conf->currency).'
'.$langs->transcountry("AmountLT2",$mysoc->pays_code).''.price($object->total_localtax2).''.$langs->trans("Currency".$conf->currency).'
'.$langs->transcountry("AmountLT1",$mysoc->pays_code).''.price($object->total_localtax1).''.$langs->trans("Currency".$conf->currency).'
'.$langs->transcountry("AmountLT2",$mysoc->pays_code).''.price($object->total_localtax2).''.$langs->trans("Currency".$conf->currency).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc).'