diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index fc91268936e..f6fcb2d652f 100755 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -24,8 +24,8 @@ */ require('../main.inc.php'); -include_once(DOL_DOCUMENT_ROOT."/compta/chargesociales.class.php"); -include_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); +include_once(DOL_DOCUMENT_ROOT."/compta/sociales/class/chargesociales.class.php"); +include_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); $langs->load("bills"); @@ -44,10 +44,12 @@ if ($user->societe_id > 0) */ if ($_POST["action"] == 'add_paiement') { + $error=0; + if ($_POST["cancel"]) { $loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid; - Header("Location: $loc"); + Header("Location: ".$loc); exit; } @@ -63,12 +65,18 @@ if ($_POST["action"] == 'add_paiement') $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date")); $error++; } + if ($conf->banque->enabled && ! $_POST["accountid"] > 0) + { + $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit")); + $error++; + } if (! $error) { - $paiement_id = 0; + $paymentid = 0; // Read possible payments + // FIXME add error message if no payment is defined $amounts = array(); foreach ($_POST as $key => $value) { @@ -90,9 +98,9 @@ if ($_POST["action"] == 'add_paiement') $paiement->paiementtype = $_POST["paiementtype"]; $paiement->num_paiement = $_POST["num_paiement"]; $paiement->note = $_POST["note"]; - $paiement_id = $paiement->create($user); + $paymentid = $paiement->create($user); - if ($paiement_id > 0) + if ($paymentid > 0) { // On determine le montant total du paiement $total=0; @@ -108,7 +116,7 @@ if ($_POST["action"] == 'add_paiement') $langs->load("banks"); $label = $langs->transnoentities("SocialContributionPayment"); $acc = new Account($db, $_POST["accountid"]); - $bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -abs($total), $paiement->num_paiement, '', $user); + $bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -$total, $paiement->num_paiement, '', $user); // Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a genere l'ecriture bancaire if ($bank_line_id > 0) @@ -125,7 +133,7 @@ if ($_POST["action"] == 'add_paiement') $db->commit(); $loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid; - Header("Location: $loc"); + Header("Location: ".$loc); exit; } else { @@ -136,7 +144,7 @@ if ($_POST["action"] == 'add_paiement') else { $db->rollback(); - $mesg = "Failed to create payment: paiement_id=$paiement_id ".$db->error(); + $mesg = "Failed to create payment: paiement_id=".$paymentid." ".$db->error(); } } @@ -208,13 +216,14 @@ if ($_GET["action"] == 'create') print ""; print ''.$langs->trans("Date").''; - $datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; + $datepaye = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0; $html->select_date($datepayment,'','','','',"add_paiement",1,1); print ""; print ''.$langs->trans("Comments").''; print ''.$langs->trans("PaymentMode").''; - $html->select_types_paiements($charge->paiementtype, "paiementtype"); + $html->select_types_paiements(isset($_POST["paiementtype"])?$_POST["paiementtype"]:$charge->paiementtype, "paiementtype"); print "\n"; print ''; @@ -222,7 +231,7 @@ if ($_GET["action"] == 'create') print ''; print ''.$langs->trans('AccountToCredit').''; print ''; - $html->select_comptes($charge->accountid, "accountid", 0, "courant=1"); // Affiche liste des comptes courant + $html->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$charge->accountid, "accountid", 0, "courant=1",1); // Affiche liste des comptes courant print ''; print ''.$langs->trans('Numero'); @@ -235,7 +244,8 @@ if ($_GET["action"] == 'create') $num = 1; $i = 0; print ''; - print ''; + + print '
'; print ''; //print ''; print '';
'.$langs->trans("SocialContribution").''.$langs->trans("DateDue").'