* Copyright (C) 2016-2018 Frédéric France * Copyright (C) 2021 Gauthier VERDOL * * 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 * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/salaries/paiement_salary.php * \ingroup salary * \brief Page to add payment of a salary */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Load translation files required by the page $langs->loadLangs(array("banks", "bills")); $action = GETPOST('action', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); $id = GETPOSTINT('id'); $ref = GETPOST('ref', 'alpha'); $amounts = array(); $object = new Salary($db); if ($id > 0 || !empty($ref)) { $object->fetch($id, $ref); } // Security check $socid = GETPOST("socid", "int"); if ($user->socid > 0) { $socid = $user->socid; } restrictedArea($user, 'salaries', $object->id, 'salary', ''); /* * Actions */ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) { $error = 0; if ($cancel) { $loc = DOL_URL_ROOT.'/salaries/card.php?id='.$id; header("Location: ".$loc); exit; } $datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int')); if (!(GETPOST("paiementtype", 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors'); $error++; $action = 'create'; } if ($datepaye == '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); $error++; $action = 'create'; } if (isModEnabled("banque") && !(GETPOST("accountid", 'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors'); $error++; $action = 'create'; } // Read possible payments foreach ($_POST as $key => $value) { if (substr($key, 0, 7) == 'amount_') { $other_chid = substr($key, 7); $amounts[$other_chid] = price2num(GETPOST($key)); } } if ($amounts[key($amounts)] <= 0) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); $action = 'create'; } if (!$error) { $paymentid = 0; if (!$error) { $db->begin(); // Create a line of payments $paiement = new PaymentSalary($db); $paiement->chid = $id; $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Tableau de montant $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml'); $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); $paiement->note = GETPOST("note", 'restricthtml'); $paiement->note_private = GETPOST("note", 'restricthtml'); if (!$error) { $paymentid = $paiement->create($user, (GETPOST('closepaidsalary') == 'on' ? 1 : 0)); if ($paymentid < 0) { $error++; setEventMessages($paiement->error, null, 'errors'); $action = 'create'; } } if (!$error) { $result = $paiement->addPaymentToBank($user, 'payment_salary', '(SalaryPayment)', GETPOST('accountid', 'int'), '', ''); if (!($result > 0)) { $error++; setEventMessages($paiement->error, null, 'errors'); $action = 'create'; } } if (!$error) { $db->commit(); $loc = DOL_URL_ROOT.'/salaries/card.php?id='.$id; header('Location: '.$loc); exit; } else { $db->rollback(); } } } } /* * View */ $form = new Form($db); $help_url = ''; llxHeader('', '', $help_url); $salary = $object; // Formulaire de creation d'un paiement de charge if ($action == 'create') { $salary->accountid = $salary->fk_account ? $salary->fk_account : $salary->accountid; $salary->paiementtype = $salary->mode_reglement_id ? $salary->mode_reglement_id : $salary->paiementtype; $total = $salary->amount; if (!empty($conf->use_javascript_ajax)) { print "\n".''."\n"; } print load_fiche_titre($langs->trans("DoPayment")); print "
\n"; print '
'; print ''; print ''; print ''; print ''; print dol_get_fiche_head(); print ''; print ''; print '\n"; print '\n"; print '\n"; /*print '\n"; print '';*/ $sql = "SELECT sum(p.amount) as total"; $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p"; $sql .= " WHERE p.fk_salary = ".((int) $id); $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); $sumpaid = $obj->total; $db->free($resql); } /*print ''; print '';*/ print '"; print ''; print '\n"; print ''; print ''; print ''; print ''; // Number print ''; print ''."\n"; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Ref").''.$id.'
'.$langs->trans("DateStart")."".dol_print_date($salary->datesp, 'day')."
'.$langs->trans("DateEnd")."".dol_print_date($salary->dateep, 'day')."
'.$langs->trans("Label").''.$salary->label."
'.$langs->trans("DateDue")."".dol_print_date($salary->date_ech,'day')."
'.$langs->trans("Amount")."".price($salary->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("AlreadyPaid").''.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Date").''; $datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int')); $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (GETPOST("remonth") ? $datepaye : -1) : ''; print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1); print "
'.$langs->trans("PaymentMode").''; $form->select_types_paiements(GETPOSTISSET("paiementtype") ? GETPOST("paiementtype") : $salary->type_payment, "paiementtype"); print "
'.$langs->trans('AccountToDebit').''; print img_picto('', 'bank_account', 'class="pictofixedwidth"'); $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", 'int') : $salary->accountid, "accountid", 0, '', 1); // Show opend bank account list print '
'.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print '
'.$langs->trans("Comments").'
'; print dol_get_fiche_end(); /* * Autres charges impayees */ $num = 1; $i = 0; print ''; print ''; //print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $total = 0; $totalrecu = 0; while ($i < $num) { $objp = $salary; print ''; if ($objp->dateep > 0) { print ''."\n"; } else { print ''."\n"; } print '"; print '"; print '"; print '"; print "\n"; $total += $objp->total; $total_ttc += $objp->total_ttc; $totalrecu += $objp->am; $i++; } if ($i > 1) { // Print total print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } print "
'.$langs->trans("SocialContribution").''.$langs->trans("DateEnd").''.$langs->trans("Amount").''.$langs->trans("AlreadyPaid").''.$langs->trans("RemainderToPay").''.$langs->trans("Amount").'
'.dol_print_date($objp->dateep, 'day').'!!!'.price($objp->amount)."'.price($sumpaid)."'.price($objp->amount - $sumpaid)."'; if ($sumpaid < $objp->amount) { $namef = "amount_".$objp->id; $nameRemain = "remain_".$objp->id; /* Disabled, we autofil the amount with remain to pay by default if (!empty($conf->use_javascript_ajax)) { print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'"); } */ $valuetoshow = GETPOSTISSET($namef) ? GETPOST($namef) : ($objp->amount - $sumpaid); print ''; print ''; } else { print '-'; } print "
'.$langs->trans("Total").':'.price($total_ttc).''.price($totalrecu).''.price($total_ttc - $totalrecu).' 
"; print '
'; // Bouton Save payment print '
'; print '
'; print $form->buttonsSaveCancel("ToMakePayment", "Cancel", '', true); print '
'; print "
\n"; } llxFooter(); $db->close();