diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 71839ecf08a..a2231a23c15 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -10,6 +10,7 @@ * Copyright (C) 2017-2020 Frédéric France * Copyright (C) 2018 Ferran Marcet * Copyright (C) 2018 Eric Seigne + * 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 @@ -45,7 +46,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; -require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; @@ -151,7 +152,7 @@ $bankaccountstatic = new Account($db); $chargestatic = new ChargeSociales($db); $paymentdonstatic = new PaymentDonation($db); $paymentvatstatic = new Tva($db); -$paymentsalstatic = new PaymentSalary($db); +$paymentsalstatic = new Salary($db); $paymentexpensereportstatic = new PaymentExpenseReport($db); $paymentvariousstatic = new PaymentVarious($db); $paymentloanstatic = new PaymentLoan($db); @@ -945,7 +946,7 @@ if (empty($action) || $action == 'view') { $vatstatic = new Tva($db); $donationstatic = new Don($db); $loanstatic = new Loan($db); - $salarystatic = new PaymentSalary($db); + $salarystatic = new Salary($db); $variousstatic = new PaymentVarious($db); llxHeader('', $langs->trans("FinanceJournal")); diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index 02098e986ba..f9c711ca5a4 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2019 Laurent Destailleur * Copyright (C) 2017 Pierre-Henry Favre * Copyright (C) 2020 Maxime DEMAREST + * 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 @@ -33,7 +34,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; -require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; @@ -189,7 +190,7 @@ if (($action == 'searchfiles' || $action == 'dl')) { $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = t.fk_user LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = u.fk_country"; $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; - //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT; + //$sql.=" AND fk_statut <> ".Salary::STATUS_DRAFT; } // Social contributions if (GETPOST('selectsocialcontributions')) { @@ -503,7 +504,7 @@ $invoice = new Facture($db); $supplier_invoice = new FactureFournisseur($db); $expensereport = new ExpenseReport($db); $don = new Don($db); -$salary_payment = new PaymentSalary($db); +$salary_payment = new Salary($db); $charge_sociales = new ChargeSociales($db); $various_payment = new PaymentVarious($db); $payment_loan = new PaymentLoan($db); diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index ae0840c5b86..feffbed15dd 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -9,6 +9,7 @@ * Copyright (C) 2017-2019 Alexandre Spangaro * Copyright (C) 2018 Ferran Marcet * Copyright (C) 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 @@ -42,13 +43,11 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; -require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; -require_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php'; require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; @@ -58,7 +57,7 @@ $langs->loadLangs(array("banks", "bills", "categories", "companies", "margins", $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); $contextpage = 'banktransactionlist'.(empty($object->ref) ? '' : '-'.$object->id); @@ -70,7 +69,9 @@ if ($fielvalue) { if ($user->socid) $socid = $user->socid; $result = restrictedArea($user, 'banque', $fieldvalue, 'bank_account&bank_account', '', '', $fieldtype); -} else { +} +else +{ if ($user->socid) $socid = $user->socid; $result = restrictedArea($user, 'banque'); } @@ -111,15 +112,15 @@ if (!$sortfield) $sortfield = 'b.datev,b.dateo,b.rowid'; $object = new Account($db); if ($id > 0 || !empty($ref)) { - $result = $object->fetch($id, $ref); - $search_account = $object->id; // Force the search field on id of account + $result = $object->fetch($id, $ref); + $search_account = $object->id; // Force the search field on id of account - if (!($object->id > 0)) - { - $langs->load("errors"); - print($langs->trans('ErrorRecordNotFound')); - exit; - } + if (!($object->id > 0)) + { + $langs->load("errors"); + print($langs->trans('ErrorRecordNotFound')); + exit; + } } $mode_balance_ok = false; @@ -139,24 +140,30 @@ $extrafields->fetch_name_optionals_label('banktransaction'); $search_array_options = $extrafields->getOptionalsFromPost('banktransaction', '', 'search_'); $arrayfields = array( - 'b.rowid'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), - 'b.label'=>array('label'=>$langs->trans("Description"), 'checked'=>1), - 'b.dateo'=>array('label'=>$langs->trans("DateOperationShort"), 'checked'=>1), - 'b.datev'=>array('label'=>$langs->trans("DateValueShort"), 'checked'=>1), - 'type'=>array('label'=>$langs->trans("Type"), 'checked'=>1), - 'b.num_chq'=>array('label'=>$langs->trans("Numero"), 'checked'=>1), - 'bu.label'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>500), - 'ba.ref'=>array('label'=>$langs->trans("BankAccount"), 'checked'=>(($id > 0 || !empty($ref)) ? 0 : 1), 'position'=>1000), - 'b.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1, 'position'=>600), - 'b.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1, 'position'=>605), + 'b.rowid'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), + 'b.label'=>array('label'=>$langs->trans("Description"), 'checked'=>1), + 'b.dateo'=>array('label'=>$langs->trans("DateOperationShort"), 'checked'=>1), + 'b.datev'=>array('label'=>$langs->trans("DateValueShort"), 'checked'=>1), + 'type'=>array('label'=>$langs->trans("Type"), 'checked'=>1), + 'b.num_chq'=>array('label'=>$langs->trans("Numero"), 'checked'=>1), + 'bu.label'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>500), + 'ba.ref'=>array('label'=>$langs->trans("BankAccount"), 'checked'=>(($id > 0 || !empty($ref)) ? 0 : 1), 'position'=>1000), + 'b.debit'=>array('label'=>$langs->trans("Debit"), 'checked'=>1, 'position'=>600), + 'b.credit'=>array('label'=>$langs->trans("Credit"), 'checked'=>1, 'position'=>605), 'balancebefore'=>array('label'=>$langs->trans("BalanceBefore"), 'checked'=>0, 'position'=>1000), 'balance'=>array('label'=>$langs->trans("Balance"), 'checked'=>1, 'position'=>1001), 'b.num_releve'=>array('label'=>$langs->trans("AccountStatement"), 'checked'=>1, 'position'=>1010), - 'b.conciliated'=>array('label'=>$langs->trans("Conciliated"), 'enabled'=> $object->rappro, 'checked'=>($action == 'reconcile' ? 1 : 0), 'position'=>1020), + 'b.conciliated'=>array('label'=>$langs->trans("Conciliated"), 'enabled'=> $object->rappro, 'checked'=>($action == 'reconcile' ? 1 : 0), 'position'=>1020), ); // Extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; - +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) +{ + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) + { + if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) + $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])); + } +} $object->fields = dol_sort_array($object->fields, 'position'); $arrayfields = dol_sort_array($arrayfields, 'position'); @@ -177,10 +184,10 @@ include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers { - $search_dt_start = ''; - $search_dt_end = ''; - $search_dv_start = ''; - $search_dv_end = ''; + $search_dt_start = ''; + $search_dt_end = ''; + $search_dv_start = ''; + $search_dv_end = ''; $search_type = ""; $search_debit = ""; $search_credit = ""; @@ -199,56 +206,60 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' if (empty($reshook)) { - $objectclass = 'Account'; - $objectlabel = 'BankTransaction'; - $permissiontoread = $user->rights->banque->lire; - $permissiontodelete = $user->rights->banque->supprimer; - $uploaddir = $conf->bank->dir_output; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + $objectclass = 'Account'; + $objectlabel = 'BankTransaction'; + $permissiontoread = $user->rights->banque->lire; + $permissiontodelete = $user->rights->banque->supprimer; + $uploaddir = $conf->bank->dir_output; + include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } // Conciliation -if ((GETPOST('confirm_savestatement', 'alpha') || GETPOST('confirm_reconcile', 'alpha')) && $user->rights->banque->consolidate - && (!GETPOSTISSET('pageplusone') || (GETPOST('pageplusone') == GETPOST('pageplusoneold')))) +if ((GETPOST('confirm_savestatement', 'alpha') || GETPOST('confirm_reconcile', 'alpha')) && $user->rights->banque->consolidate) { - $error = 0; + $error = 0; - // Definition, nettoyage parametres - $num_releve = GETPOST("num_releve", "alpha"); + // Definition, nettoyage parametres + $num_releve = trim(GETPOST("num_releve", "alpha")); - if ($num_releve) - { - $bankline = new AccountLine($db); + if ($num_releve) + { + $bankline = new AccountLine($db); + if (isset($_POST['rowid']) && is_array($_POST['rowid'])) + { + foreach ($_POST['rowid'] as $row) + { + if ($row > 0) + { + $result = $bankline->fetch($row); + $bankline->num_releve = $num_releve; //$_POST["num_releve"]; + $result = $bankline->update_conciliation($user, GETPOST("cat"), GETPOST('confirm_reconcile', 'alpha') ? 1 : 0); // If we confirm_reconcile, we set flag 'rappro' to 1. + if ($result < 0) + { + setEventMessages($bankline->error, $bankline->errors, 'errors'); + $error++; + break; + } + } + } + } + else + { + $error++; + $langs->load("errors"); + setEventMessages($langs->trans("NoRecordSelected"), null, 'errors'); + } + } + else + { + $error++; + $langs->load("errors"); + setEventMessages($langs->trans("ErrorPleaseTypeBankTransactionReportName"), null, 'errors'); + } - $rowids = GETPOST('rowid', 'array'); - - if (!empty($rowids) && is_array($rowids)) { - foreach ($rowids as $row) { - if ($row > 0) { - $result = $bankline->fetch($row); - $bankline->num_releve = $num_releve; //$_POST["num_releve"]; - $result = $bankline->update_conciliation($user, GETPOST("cat"), GETPOST('confirm_reconcile', 'alpha') ? 1 : 0); // If we confirm_reconcile, we set flag 'rappro' to 1. - if ($result < 0) { - setEventMessages($bankline->error, $bankline->errors, 'errors'); - $error++; - break; - } - } - } - } else { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans("NoRecordSelected"), null, 'errors'); - } - } else { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans("ErrorPleaseTypeBankTransactionReportName"), null, 'errors'); - } - - if (!$error) - { - $param = 'action=reconcile&contextpage=banktransactionlist&id='.$id.'&search_account='.$id; + if (!$error) + { + $param = 'action=reconcile&contextpage=banktransactionlist&id='.$id.'&search_account='.$id; $param .= '&search_conciliated='.urlencode($search_conciliated); if ($page) $param .= '&page='.urlencode($page); if ($offset) $param .= '&offset='.urlencode($offset); @@ -264,84 +275,91 @@ if ((GETPOST('confirm_savestatement', 'alpha') || GETPOST('confirm_reconcile', ' if ($search_credit) $param .= '&search_credit='.urlencode($search_credit); $param .= '&sortfield='.urlencode($sortfield).'&sortorder='.urlencode($sortorder); header('Location: '.$_SERVER["PHP_SELF"].'?'.$param); // To avoid to submit twice and allow the back button - exit; - } + exit; + } } if (GETPOST('save') && !$cancel && $user->rights->banque->modifier) { - $error = 0; + $error = 0; - if (price2num(GETPOST("addcredit")) > 0) - { - $amount = price2num(GETPOST("addcredit")); - } else { - $amount = - price2num(GETPOST("adddebit")); - } + if (price2num($_POST["addcredit"]) > 0) + { + $amount = price2num($_POST["addcredit"]); + } + else + { + $amount = - price2num($_POST["adddebit"]); + } - $operation = GETPOST("operation", 'alpha'); - $num_chq = GETPOST("num_chq", 'alpha'); - $label = GETPOST("label", 'alpha'); - $cat1 = GETPOST("cat1", 'alpha'); + $operation = GETPOST("operation", 'alpha'); + $num_chq = GETPOST("num_chq", 'alpha'); + $label = GETPOST("label", 'alpha'); + $cat1 = GETPOST("cat1", 'alpha'); - $bankaccountid = $id; - if (GETPOST('add_account', 'int') > 0) { - $bankaccountid = GETPOST('add_account', 'int'); - } - if (!$dateop) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); - } - if (!$operation) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); - } - if (!$label) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); - } - if (!$amount) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors'); - } - if (!$bankaccountid > 0) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors'); - } - /*if (! empty($conf->accounting->enabled) && (empty($search_accountancy_code) || $search_accountancy_code == '-1')) + $bankaccountid = $id; + if (GETPOST('add_account', 'int') > 0) $bankaccountid = GETPOST('add_account', 'int'); + + if (!$dateop) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); + } + if (!$operation) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); + } + if (!$label) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); + } + if (!$amount) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors'); + } + if (!$bankaccountid > 0) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors'); + } + /*if (! empty($conf->accounting->enabled) && (empty($search_accountancy_code) || $search_accountancy_code == '-1')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors'); $error++; }*/ - if (!$error && !empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) { - $objecttmp = new Account($db); - $objecttmp->fetch($bankaccountid); - $insertid = $objecttmp->addline($dateop, $operation, $label, $amount, $num_chq, ($cat1 > 0 ? $cat1 : 0), $user, '', '', $search_accountancy_code); - if ($insertid > 0) - { - setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); - header("Location: ".$_SERVER['PHP_SELF'].($id ? "?id=".$id : '')); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - $action = 'addline'; - } + if (!$error && !empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) + { + $objecttmp = new Account($db); + $objecttmp->fetch($bankaccountid); + $insertid = $objecttmp->addline($dateop, $operation, $label, $amount, $num_chq, ($cat1 > 0 ? $cat1 : 0), $user, '', '', $search_accountancy_code); + if ($insertid > 0) + { + setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); + header("Location: ".$_SERVER['PHP_SELF'].($id ? "?id=".$id : '')); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + else + { + $action = 'addline'; + } } if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->modifier) { - $accline = new AccountLine($db); - $result = $accline->fetch(GETPOST("rowid", "int")); - $result = $accline->delete($user); - if ($result <= 0) { - setEventMessages($accline->error, $accline->errors, 'errors'); - } else { - setEventMessages('RecordDeleted', null, 'mesgs'); - } + $accline = new AccountLine($db); + $result = $accline->fetch(GETPOST("rowid", "int")); + $result = $accline->delete($user); + if ($result <= 0) { + setEventMessages($accline->error, $accline->errors, 'errors'); + } else { + setEventMessages('RecordDeleted', null, 'mesgs'); + } } @@ -363,14 +381,12 @@ $userstatic = new User($db); $chargestatic = new ChargeSociales($db); $loanstatic = new Loan($db); $memberstatic = new Adherent($db); -$donstatic = new Don($db); $paymentstatic = new Paiement($db); $paymentsupplierstatic = new PaiementFourn($db); -$paymentscstatic = new PaymentSocialContribution($db); -$paymentvatstatic = new Tva($db); -$paymentsalstatic = new PaymentSalary($db); -$paymentdonationstatic = new PaymentDonation($db); +$paymentvatstatic = new TVA($db); +$paymentsalstatic = new Salary($db); $paymentvariousstatic = new PaymentVarious($db); +$donstatic = new Don($db); $paymentexpensereportstatic = new PaymentExpenseReport($db); $bankstatic = new Account($db); $banklinestatic = new AccountLine($db); @@ -416,44 +432,46 @@ if ($id > 0 || !empty($ref)) $helpurl = ""; llxHeader('', $title, $helpurl); - // Load bank groups - require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php'; - $bankcateg = new BankCateg($db); + // Load bank groups + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php'; + $bankcateg = new BankCateg($db); - foreach ($bankcateg->fetchAll() as $bankcategory) { - $options[$bankcategory->id] = $bankcategory->label; - } + foreach ($bankcateg->fetchAll() as $bankcategory) { + $options[$bankcategory->id] = $bankcategory->label; + } - // Bank card - $head = bank_prepare_head($object); - print dol_get_fiche_head($head, 'journal', $langs->trans("FinancialAccount"), 0, 'account'); + // Bank card + $head = bank_prepare_head($object); + dol_fiche_head($head, 'journal', $langs->trans("FinancialAccount"), 0, 'account'); - $linkback = ''.$langs->trans("BackToList").''; + $linkback = ''.$langs->trans("BackToList").''; - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); - print dol_get_fiche_end(); + dol_fiche_end(); - /* + /* * Buttons actions */ - if ($action != 'reconcile') - { - if ($object->canBeConciliated() > 0) - { - // If not cash account and can be reconciliate - if ($user->rights->banque->consolidate) { - $newparam = $param; - $newparam = preg_replace('/search_conciliated=\d+/i', '', $newparam); - $buttonreconcile = ''.$langs->trans("Conciliate").''; - } else { - $buttonreconcile = ''.$langs->trans("Conciliate").''; - } - } - } -} else { + if ($action != 'reconcile') + { + if ($object->canBeConciliated() > 0) + { + // If not cash account and can be reconciliate + if ($user->rights->banque->consolidate) { + $newparam = $param; + $newparam = preg_replace('/search_conciliated=\d+/i', '', $newparam); + $buttonreconcile = ''.$langs->trans("Conciliate").''; + } else { + $buttonreconcile = ''.$langs->trans("Conciliate").''; + } + } + } +} +else +{ llxHeader('', $langs->trans("BankTransactions"), '', '', 0, 0, array(), array(), $param); } @@ -489,7 +507,7 @@ if (dol_strlen($search_dv_end) > 0) $sql .= " AND b.datev <= '".$db->idate($sear if ($search_ref) $sql .= natural_search("b.rowid", $search_ref, 1); if ($search_req_nb) $sql .= natural_search("b.num_chq", $search_req_nb); if ($search_num_releve) $sql .= natural_search("b.num_releve", $search_num_releve); -if ($search_conciliated != '' && $search_conciliated != '-1') $sql .= " AND b.rappro = ".urlencode($search_conciliated); +if ($search_conciliated != '' && $search_conciliated != '-1') $sql .= " AND b.rappro = ".$search_conciliated; if ($search_thirdparty) $sql .= natural_search("s.nom", $search_thirdparty); if ($search_description) { @@ -535,25 +553,25 @@ $nbtotalofrecords = ''; $nbtotalofpages = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); - $nbtotalofpages = ceil($nbtotalofrecords / $limit); + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); + $nbtotalofpages = ceil($nbtotalofrecords / $limit); } if (($id > 0 || !empty($ref)) && ((string) $page == '')) { - // We open a list of transaction of a dedicated account and no page was set by defaut - // We force on last page. - $page = ($nbtotalofpages - 1); - $offset = $limit * $page; - if ($page < 0) $page = 0; + // We open a list of transaction of a dedicated account and no page was set by defaut + // We force on last page. + $page = ($nbtotalofpages - 1); + $offset = $limit * $page; + if ($page < 0) $page = 0; } if ($page >= $nbtotalofpages) { - // If we made a search and result has low page than the page number we were on - $page = ($nbtotalofpages - 1); - $offset = $limit * $page; - if ($page < 0) $page = 0; + // If we made a search and result has low page than the page number we were on + $page = ($nbtotalofpages - 1); + $offset = $limit * $page; + if ($page < 0) $page = 0; } @@ -579,23 +597,23 @@ if ($resql) $arrayofselected = is_array($toselect) ? $toselect : array(); - // List of mass actions available - $arrayofmassactions = array( - //'presend'=>$langs->trans("SendByMail"), - //'builddoc'=>$langs->trans("PDFMerge"), - ); - //if ($user->rights->bank->supprimer) $arrayofmassactions['predelete']=''.$langs->trans("Delete"); - if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); - $massactionbutton = $form->selectMassAction('', $arrayofmassactions); + // List of mass actions available + $arrayofmassactions = array( + //'presend'=>$langs->trans("SendByMail"), + //'builddoc'=>$langs->trans("PDFMerge"), + ); + //if ($user->rights->bank->supprimer) $arrayofmassactions['predelete']=''.$langs->trans("Delete"); + if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); + $massactionbutton = $form->selectMassAction('', $arrayofmassactions); - // Confirmation delete - if ($action == 'delete') - { - $text = $langs->trans('ConfirmDeleteTransaction'); - print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&rowid='.GETPOST("rowid"), $langs->trans('DeleteTransaction'), $text, 'confirm_delete', null, '', 1); - } + // Confirmation delete + if ($action == 'delete') + { + $text = $langs->trans('ConfirmDeleteTransaction'); + print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&rowid='.GETPOST("rowid"), $langs->trans('DeleteTransaction'), $text, 'confirm_delete', null, '', 1); + } - // Lines of title fields + // Lines of title fields print '
'."\n"; if ($optioncss != '') print ''; print ''; @@ -604,7 +622,7 @@ if ($resql) print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; if (GETPOST('bid')) print ''; @@ -612,54 +630,56 @@ if ($resql) // Form to reconcile if ($user->rights->banque->consolidate && $action == 'reconcile') { - print '
'; - print ''.$langs->trans("InputReceiptNumber").': '; - print ''; // The only default value is value we just entered - print '
'; - if (is_array($options) && count($options)) - { - print $langs->trans("EventualyAddCategory").': '; - print Form::selectarray('cat', $options, GETPOST('cat'), 1); - } - print '
'.$langs->trans("ThenCheckLinesAndConciliate").' '; - print ''; - print ' '.$langs->trans("or").' '; - print ''; - print ' '.$langs->trans("or").' '; - print ''; + print '
'; + print ''.$langs->trans("InputReceiptNumber").': '; + print ''; // The only default value is value we just entered + print '
'; + if (is_array($options) && count($options)) + { + print $langs->trans("EventualyAddCategory").': '; + print Form::selectarray('cat', $options, GETPOST('cat'), 1); + } + print '
'.$langs->trans("ThenCheckLinesAndConciliate").' '; + print ''; + print ' '.$langs->trans("or").' '; + print ''; + print ' '.$langs->trans("or").' '; + print ''; print '
'; - // Show last bank statements - $nbmax = 12; // We show last 12 receipts (so we can have more than one year) - $liste = ""; - $sql = "SELECT DISTINCT num_releve FROM ".MAIN_DB_PREFIX."bank"; - $sql .= " WHERE fk_account=".$object->id." AND num_releve IS NOT NULL"; - $sql .= $db->order("num_releve", "DESC"); - $sql .= $db->plimit($nbmax + 1); - print '
'; - print $langs->trans("LastAccountStatements").' : '; - $resqlr = $db->query($sql); - if ($resqlr) - { - $numr = $db->num_rows($resqlr); - $i = 0; - $last_ok = 0; - while (($i < $numr) && ($i < $nbmax)) - { - $objr = $db->fetch_object($resqlr); - if (!$last_ok) { - $last_releve = $objr->num_releve; - $last_ok = 1; - } - $i++; - $liste = ''.$objr->num_releve.'   '.$liste; - } - if ($numr >= $nbmax) $liste = "...   ".$liste; - print $liste; - if ($numr <= 0) print ''.$langs->trans("None").''; - } else { - dol_print_error($db); - } + // Show last bank statements + $nbmax = 15; // We accept to show last 15 receipts (so we can have more than one year) + $liste = ""; + $sql = "SELECT DISTINCT num_releve FROM ".MAIN_DB_PREFIX."bank"; + $sql .= " WHERE fk_account=".$object->id." AND num_releve IS NOT NULL"; + $sql .= $db->order("num_releve", "DESC"); + $sql .= $db->plimit($nbmax + 1); + print '
'; + print $langs->trans("LastAccountStatements").' : '; + $resqlr = $db->query($sql); + if ($resqlr) + { + $numr = $db->num_rows($resqlr); + $i = 0; + $last_ok = 0; + while (($i < $numr) && ($i < $nbmax)) + { + $objr = $db->fetch_object($resqlr); + if (!$last_ok) { + $last_releve = $objr->num_releve; + $last_ok = 1; + } + $i++; + $liste = ''.$objr->num_releve.'   '.$liste; + } + if ($numr >= $nbmax) $liste = "...   ".$liste; + print $liste; + if ($numr <= 0) print ''.$langs->trans("None").''; + } + else + { + dol_print_error($db); + } // Using BANK_REPORT_LAST_NUM_RELEVE to automatically report last num (or not) if (!empty($conf->global->BANK_REPORT_LAST_NUM_RELEVE)) @@ -733,7 +753,7 @@ if ($resql) }*/ print ''; print '
'; - print ''; + print ''; print ''; print ''; @@ -770,24 +790,26 @@ if ($resql) { if (empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) { - if (empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) // Default is to record miscellaneous direct entries using miscellaneous payments + if (empty($conf->global->BANK_USE_OLD_VARIOUS_PAYMENT)) // If direct entries is done using miscellaneous payments { - $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create&accountid='.$search_account.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.urlencode($search_account)), '', $user->rights->banque->modifier); - } else // If direct entries is not done using miscellaneous payments - { - $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&page='.$page.$param, '', $user->rights->banque->modifier); + $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create&accountid='.$search_account.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.urlencode($search_account)), '', $user->rights->banque->modifier); } - } else { - $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&page='.$page.$param, '', -1); + else // If direct entries is not done using miscellaneous payments + { + $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&page='.$page.$param, '', $user->rights->banque->modifier); + } + } + else + { + $newcardbutton = dolGetButtonTitle($langs->trans('AddBankRecord'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=addline&page='.$page.$param, '', -1); } } - /*$morehtml = '
'; + $morehtml = '
'; $morehtml .= ' "; // ' Page '; $morehtml .= ''; $morehtml .= '/'.$nbtotalofpages.' '; $morehtml .= '
'; - */ if ($action != 'addline' && $action != 'reconcile') { @@ -799,7 +821,7 @@ if ($resql) $picto = 'bank_account'; if ($id > 0 || !empty($ref)) $picto = ''; - print_barre_liste($langs->trans("BankTransactions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit, 0, 0, 1); + print_barre_liste($langs->trans("BankTransactions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit); // We can add page now to param if ($page != '') $param .= '&page='.urlencode($page); @@ -809,19 +831,19 @@ if ($resql) $moreforfilter .= '
'; $moreforfilter .= $langs->trans('DateOperationShort').' :'; $moreforfilter .= ($conf->browser->layout == 'phone' ? '
' : ' '); - $moreforfilter .= '
'; - $moreforfilter .= $form->selectDate($search_dt_start, 'search_start_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')).'
'; + $moreforfilter .= '
'.$langs->trans('From').' '; + $moreforfilter .= $form->selectDate($search_dt_start, 'search_start_dt', 0, 0, 1, "search_form", 1, 0).'
'; //$moreforfilter .= ' - '; - $moreforfilter .= '
'.$form->selectDate($search_dt_end, 'search_end_dt', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')).'
'; + $moreforfilter .= '
'.$langs->trans('to').' '.$form->selectDate($search_dt_end, 'search_end_dt', 0, 0, 1, "search_form", 1, 0).'
'; $moreforfilter .= '
'; $moreforfilter .= '
'; $moreforfilter .= $langs->trans('DateValueShort').' : '; $moreforfilter .= ($conf->browser->layout == 'phone' ? '
' : ' '); - $moreforfilter .= '
'; - $moreforfilter .= $form->selectDate($search_dv_start, 'search_start_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')).'
'; + $moreforfilter .= '
'.$langs->trans('From').' '; + $moreforfilter .= $form->selectDate($search_dv_start, 'search_start_dv', 0, 0, 1, "search_form", 1, 0).'
'; //$moreforfilter .= ' - '; - $moreforfilter .= '
'.$form->selectDate($search_dv_end, 'search_end_dv', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')).'
'; + $moreforfilter .= '
'.$langs->trans('to').' '.$form->selectDate($search_dv_end, 'search_end_dv', 0, 0, 1, "search_form", 1, 0).'
'; $moreforfilter .= '
'; if (!empty($conf->categorie->enabled)) @@ -835,7 +857,7 @@ if ($resql) $moreforfilter .= '
'; $moreforfilter .= $langs->trans('RubriquesTransactions').' : '; $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, $search_bid, 'parent', null, null, 1); - $moreforfilter .= $form->selectarray('search_bid', $cate_arbo, $search_bid, 1, 0, 0, '', 0, 0, 0, '', '', 1); + $moreforfilter .= $form->selectarray('search_bid', $cate_arbo, $search_bid, 1); $moreforfilter .= '
'; } } @@ -852,70 +874,66 @@ if ($resql) print '
'."\n"; } - $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; - $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - // When action is 'reconcile', we force to have the column num_releve always enabled (otherwise we can't make reconciliation). - if ($action == 'reconcile') { - $arrayfields['b.num_releve']['checked'] = 1; - } + $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; + $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - print '
'; - print ''."\n"; + print '
'; + print '
'."\n"; print ''; if (!empty($arrayfields['b.rowid']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['b.label']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['b.dateo']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['b.datev']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['type']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['b.num_chq']['checked'])) { - // Numero - print ''; + // Numero + print ''; } if (!empty($arrayfields['bu.label']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['ba.ref']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['b.debit']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['b.credit']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['balancebefore']['checked'])) { @@ -934,21 +952,21 @@ if ($resql) // Numero statement if (!empty($arrayfields['b.num_releve']['checked'])) { - print ''; + print ''; } // Conciliated if (!empty($arrayfields['b.conciliated']['checked'])) { - print ''; + print ''; } print ''; print ''; + print ''; print "\n"; // Fields title @@ -986,366 +1004,385 @@ if ($resql) // Loop on each record $sign = 1; - $totalarray = array(); - while ($i < min($num, $limit)) - { - $objp = $db->fetch_object($resql); - // If we are in a situation where we need/can show balance, we calculate the start of balance - if (!$balancecalculated && (!empty($arrayfields['balancebefore']['checked']) || !empty($arrayfields['balance']['checked'])) && ($mode_balance_ok || $search_conciliated === '0')) - { - if (!$search_account) - { - dol_print_error('', 'account is not defined but $mode_balance_ok is true'); - exit; - } + $totalarray = array(); + while ($i < min($num, $limit)) + { + $objp = $db->fetch_object($resql); - // Loop on each record before - $sign = 1; - $i = 0; - $sqlforbalance = 'SELECT SUM(b.amount) as previoustotal'; - $sqlforbalance .= " FROM "; - $sqlforbalance .= " ".MAIN_DB_PREFIX."bank_account as ba,"; - $sqlforbalance .= " ".MAIN_DB_PREFIX."bank as b"; - $sqlforbalance .= " WHERE b.fk_account = ba.rowid"; - $sqlforbalance .= " AND ba.entity IN (".getEntity('bank_account').")"; - $sqlforbalance .= " AND b.fk_account = ".$search_account; - $sqlforbalance .= " AND (b.datev < '".$db->idate($db->jdate($objp->dv))."' OR (b.datev = '".$db->idate($db->jdate($objp->dv))."' AND (b.dateo < '".$db->idate($db->jdate($objp->do))."' OR (b.dateo = '".$db->idate($db->jdate($objp->do))."' AND b.rowid < ".$objp->rowid."))))"; - $resqlforbalance = $db->query($sqlforbalance); - //print $sqlforbalance; - if ($resqlforbalance) { - $objforbalance = $db->fetch_object($resqlforbalance); - if ($objforbalance) { - // If sort is desc,desc,desc then total of previous date + amount is the balancebefore of the previous line before the line to show - if ($sortfield == 'b.datev,b.dateo,b.rowid' && $sortorder == 'desc,desc,desc') - { - $balancebefore = $objforbalance->previoustotal + ($sign * $objp->amount); - } // If sort is asc,asc,asc then total of previous date is balance of line before the next line to show - else { - $balance = $objforbalance->previoustotal; - } - } - } else dol_print_error($db); + // If we are in a situation where we need/can show balance, we calculate the start of balance + if (!$balancecalculated && (!empty($arrayfields['balancebefore']['checked']) || !empty($arrayfields['balance']['checked'])) && $mode_balance_ok) + { + if (!$search_account) + { + dol_print_error('', 'account is not defined but $mode_balance_ok is true'); + exit; + } - $balancecalculated = true; + // Loop on each record before + $sign = 1; + $i = 0; + $sqlforbalance = 'SELECT SUM(b.amount) as previoustotal'; + $sqlforbalance .= " FROM "; + $sqlforbalance .= " ".MAIN_DB_PREFIX."bank_account as ba,"; + $sqlforbalance .= " ".MAIN_DB_PREFIX."bank as b"; + $sqlforbalance .= " WHERE b.fk_account = ba.rowid"; + $sqlforbalance .= " AND ba.entity IN (".getEntity('bank_account').")"; + $sqlforbalance .= " AND b.fk_account = ".$search_account; + $sqlforbalance .= " AND (b.datev < '".$db->idate($db->jdate($objp->dv))."' OR (b.datev = '".$db->idate($db->jdate($objp->dv))."' AND (b.dateo < '".$db->idate($db->jdate($objp->do))."' OR (b.dateo = '".$db->idate($db->jdate($objp->do))."' AND b.rowid < ".$objp->rowid."))))"; + $resqlforbalance = $db->query($sqlforbalance); + //print $sqlforbalance; + if ($resqlforbalance) + { + $objforbalance = $db->fetch_object($resqlforbalance); + if ($objforbalance) + { + // If sort is desc,desc,desc then total of previous date + amount is the balancebefore of the previous line before the line to show + if ($sortfield == 'b.datev,b.dateo,b.rowid' && $sortorder == 'desc,desc,desc') + { + $balancebefore = $objforbalance->previoustotal + ($sign * $objp->amount); + } + // If sort is asc,asc,asc then total of previous date is balance of line before the next line to show + else + { + $balance = $objforbalance->previoustotal; + } + } + } + else dol_print_error($db); - // Output a line with start balance - if ($user->rights->banque->consolidate && $action == 'reconcile') - { - $tmpnbfieldbeforebalance = 0; - $tmpnbfieldafterbalance = 0; - $balancefieldfound = 0; - foreach ($arrayfields as $key => $val) - { - if ($key == 'balancebefore' || $key == 'balance') - { - $balancefieldfound++; - continue; - } - if (!empty($arrayfields[$key]['checked'])) - { - if (!$balancefieldfound) $tmpnbfieldbeforebalance++; - else $tmpnbfieldafterbalance++; - } - } - // Extra fields - $element = 'banktransaction'; - if (is_array($extrafields->attributes[$element]['label']) && count($extrafields->attributes[$element]['label'])) - { - foreach ($extrafields->attributes[$element]['label'] as $key => $val) - { - if (!empty($arrayfields["ef.".$key]['checked'])) - { - if (!empty($arrayfields[$key]['checked'])) - { - if (!$balancefieldfound) $tmpnbfieldbeforebalance++; - else $tmpnbfieldafterbalance++; - } - } - } - } + $balancecalculated = true; - print ''; - if ($tmpnbfieldbeforebalance) - { - print ''; + if ($tmpnbfieldbeforebalance) + { + print ''; + } + + if (!empty($arrayfields['balancebefore']['checked'])) + { + print ''; + } + if (!empty($arrayfields['balance']['checked'])) + { + print ''; - } + } - if (!empty($arrayfields['balancebefore']['checked'])) - { - print ''; - } - if (!empty($arrayfields['balance']['checked'])) - { - print ''; - } - if (!empty($arrayfields['b.num_releve']['checked'])) - { - print ''; - } + print ''; print ''; - print ''; - } - } + print ''; + } + } - if ($sortfield == 'b.datev,b.dateo,b.rowid' && $sortorder == 'desc,desc,desc') + if ($sortfield == 'b.datev,b.dateo,b.rowid' && $sortorder == 'desc,desc,desc') + { + $balance = price2num($balancebefore, 'MT'); // balance = balancebefore of previous line (sort is desc) + $balancebefore = price2num($balancebefore - ($sign * $objp->amount), 'MT'); + } + else { - $balance = price2num($balancebefore, 'MT'); // balance = balancebefore of previous line (sort is desc) - $balancebefore = price2num($balancebefore - ($sign * $objp->amount), 'MT'); - } else { $balancebefore = price2num($balance, 'MT'); // balancebefore = balance of previous line (sort is asc) $balance = price2num($balance + ($sign * $objp->amount), 'MT'); } - if (empty($cachebankaccount[$objp->bankid])) - { - $bankaccounttmp = new Account($db); - $bankaccounttmp->fetch($objp->bankid); - $cachebankaccount[$objp->bankid] = $bankaccounttmp; - $bankaccount = $bankaccounttmp; - } else { - $bankaccount = $cachebankaccount[$objp->bankid]; - } + if (empty($cachebankaccount[$objp->bankid])) + { + $bankaccounttmp = new Account($db); + $bankaccounttmp->fetch($objp->bankid); + $cachebankaccount[$objp->bankid] = $bankaccounttmp; + $bankaccount = $bankaccounttmp; + } + else + { + $bankaccount = $cachebankaccount[$objp->bankid]; + } - if (empty($conf->global->BANK_COLORIZE_MOVEMENT)) { - $backgroundcolor = "class='oddeven'"; - } else { - if ($objp->amount < 0) - { - if (empty($conf->global->BANK_COLORIZE_MOVEMENT_COLOR1)) { - $color = '#fca955'; - } else { - $color = '#'.$conf->global->BANK_COLORIZE_MOVEMENT_COLOR1; - } - $backgroundcolor = 'style="background: '.$color.';"'; - } else { - if (empty($conf->global->BANK_COLORIZE_MOVEMENT_COLOR2)) { - $color = '#7fdb86'; - } else { - $color = '#'.$conf->global->BANK_COLORIZE_MOVEMENT_COLOR2; - } - $backgroundcolor = 'style="background: '.$color.';"'; - } - } + if (empty($conf->global->BANK_COLORIZE_MOVEMENT)) { + $backgroundcolor = "class='oddeven'"; + } else { + if ($objp->amount < 0) + { + if (empty($conf->global->BANK_COLORIZE_MOVEMENT_COLOR1)) { + $color = '#fca955'; + } else { + $color = '#'.$conf->global->BANK_COLORIZE_MOVEMENT_COLOR1; + } + $backgroundcolor = 'style="background: '.$color.';"'; + } else { + if (empty($conf->global->BANK_COLORIZE_MOVEMENT_COLOR2)) { + $color = '#7fdb86'; + } else { + $color = '#'.$conf->global->BANK_COLORIZE_MOVEMENT_COLOR2; + } + $backgroundcolor = 'style="background: '.$color.';"'; + } + } + print ''; - $banklinestatic->id = $objp->rowid; - $banklinestatic->ref = $objp->rowid; + // Ref + if (!empty($arrayfields['b.rowid']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } - print ''; + // Description + if (!empty($arrayfields['b.label']['checked'])) + { + print "'; - if (!$i) $totalarray['nbfield']++; - } + //print "rowid."&account=".$objp->fk_account."\">"; + $reg = array(); + preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthee on tente recherche de traduction + if ($reg[1] && $langs->trans($reg[1]) != $reg[1]) print $langs->trans($reg[1]); + else { + if ($objp->label == '(payment_salary)') { + print dol_trunc($langs->trans("SalaryPayment", 40)); + } else { + print dol_trunc($objp->label, 40); + } + } + //print " "; - // Description - if (!empty($arrayfields['b.label']['checked'])) - { - print "'; + if (!$i) $totalarray['nbfield']++; + } - //print "rowid."&account=".$objp->fk_account."\">"; - $reg = array(); - preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthee on tente recherche de traduction - if ($reg[1] && $langs->trans($reg[1]) != $reg[1]) print $langs->trans($reg[1]); - else { - if ($objp->label == '(payment_salary)') { - print dol_trunc($langs->trans("SalaryPayment", 40)); - } else { - print dol_trunc($objp->label, 40); - } - } - //print " "; + // Date ope + if (!empty($arrayfields['b.dateo']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + } - // Add links after description - $links = $bankaccountstatic->get_url($objp->rowid); - $cachebankaccount = array(); - foreach ($links as $key=>$val) - { - print ''; - if ($links[$key]['type'] == 'withdraw') - { - $banktransferstatic->id = $links[$key]['url_id']; - $banktransferstatic->ref = $links[$key]['label']; - print ' '.$banktransferstatic->getNomUrl(0); - } elseif ($links[$key]['type'] == 'payment') - { - $paymentstatic->id = $links[$key]['url_id']; - $paymentstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment - print ' '.$paymentstatic->getNomUrl(2); - } elseif ($links[$key]['type'] == 'payment_supplier') - { - $paymentsupplierstatic->id = $links[$key]['url_id']; - $paymentsupplierstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment - print ' '.$paymentsupplierstatic->getNomUrl(2); - } elseif ($links[$key]['type'] == 'payment_sc') - { - $paymentscstatic->id = $links[$key]['url_id']; - $paymentscstatic->ref = $links[$key]['url_id']; - $paymentscstatic->label = $links[$key]['label']; - print ' '.$paymentscstatic->getNomUrl(2); - } elseif ($links[$key]['type'] == 'payment_vat') - { - $paymentvatstatic->id = $links[$key]['url_id']; - $paymentvatstatic->ref = $links[$key]['url_id']; - print ' '.$paymentvatstatic->getNomUrl(2); - } elseif ($links[$key]['type'] == 'payment_salary') - { - $paymentsalstatic->id = $links[$key]['url_id']; - $paymentsalstatic->ref = $links[$key]['url_id']; - $paymentsalstatic->label = $links[$key]['label']; - print ' '.$paymentsalstatic->getNomUrl(2); - } elseif ($links[$key]['type'] == 'payment_loan') - { - print ''; - print ' '.img_object($langs->trans('ShowPayment'), 'payment').' '; - print ''; - } elseif ($links[$key]['type'] == 'payment_donation') - { - $paymentdonationstatic->id = $links[$key]['url_id']; - $paymentdonationstatic->ref = $links[$key]['url_id']; - print ' '.$paymentdonationstatic->getNomUrl(2); - } elseif ($links[$key]['type'] == 'payment_expensereport') - { - $paymentexpensereportstatic->id = $links[$key]['url_id']; - $paymentexpensereportstatic->ref = $links[$key]['url_id']; - print ' '.$paymentexpensereportstatic->getNomUrl(2); - } elseif ($links[$key]['type'] == 'payment_various') - { - $paymentvariousstatic->id = $links[$key]['url_id']; - $paymentvariousstatic->ref = $links[$key]['url_id']; - print ' '.$paymentvariousstatic->getNomUrl(2); - } elseif ($links[$key]['type'] == 'banktransfert') - { - // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail. - if ($objp->amount > 0) - { - $banklinestatic->fetch($links[$key]['url_id']); - $bankstatic->id = $banklinestatic->fk_account; - $bankstatic->label = $banklinestatic->bank_account_ref; - print ' ('.$langs->trans("TransferFrom").' '; - print $bankstatic->getNomUrl(1, 'transactions'); - print ' '.$langs->trans("toward").' '; - $bankstatic->id = $objp->bankid; - $bankstatic->label = $objp->bankref; - print $bankstatic->getNomUrl(1, ''); - print ')'; - } else { - $bankstatic->id = $objp->bankid; - $bankstatic->label = $objp->bankref; - print ' ('.$langs->trans("TransferFrom").' '; - print $bankstatic->getNomUrl(1, ''); - print ' '.$langs->trans("toward").' '; - $banklinestatic->fetch($links[$key]['url_id']); - $bankstatic->id = $banklinestatic->fk_account; - $bankstatic->label = $banklinestatic->bank_account_ref; - print $bankstatic->getNomUrl(1, 'transactions'); - print ')'; - } - //var_dump($links); - } elseif ($links[$key]['type'] == 'company') - { - } elseif ($links[$key]['type'] == 'user') - { - } elseif ($links[$key]['type'] == 'member') - { - } elseif ($links[$key]['type'] == 'sc') - { - } else { - // Show link with label $links[$key]['label'] - if (!empty($objp->label) && !empty($links[$key]['label'])) print ' - '; - print ''; - if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) - { - // Label generique car entre parentheses. On l'affiche en le traduisant - if ($reg[1] == 'paiement') $reg[1] = 'Payment'; - print ' '.$langs->trans($reg[1]); - } else { - print ' '.$links[$key]['label']; - } - print ''; - } - } - print ''; - if (!$i) $totalarray['nbfield']++; - } + // Date value + if (!empty($arrayfields['b.datev']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + } - // Date ope - if (!empty($arrayfields['b.dateo']['checked'])) - { - print '\n"; - if (!$i) $totalarray['nbfield']++; - } + // Payment type + if (!empty($arrayfields['type']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + } - // Date value - if (!empty($arrayfields['b.datev']['checked'])) - { - print '\n"; - if (!$i) $totalarray['nbfield']++; - } - - // Payment type - if (!empty($arrayfields['type']['checked'])) - { - print '\n"; - if (!$i) $totalarray['nbfield']++; - } - - // Num cheque - if (!empty($arrayfields['b.num_chq']['checked'])) - { - print '\n"; - if (!$i) $totalarray['nbfield']++; - } + // Num cheque + if (!empty($arrayfields['b.num_chq']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + } // Third party - if (!empty($arrayfields['bu.label']['checked'])) - { - print ''; - if (!$i) $totalarray['nbfield']++; - } + if (!$i) $totalarray['nbfield']++; + } - // Bank account - if (!empty($arrayfields['ba.ref']['checked'])) - { - print '\n"; - if (!$i) $totalarray['nbfield']++; - } + if (!$i) $totalarray['nbfield']++; + } - // Debit - if (!empty($arrayfields['b.debit']['checked'])) - { - print '\n"; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['totaldebfield'] = $totalarray['nbfield']; - } + // Debit + if (!empty($arrayfields['b.debit']['checked'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['totaldebfield'] = $totalarray['nbfield']; + } - // Credit - if (!empty($arrayfields['b.credit']['checked'])) - { - print '\n"; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['totalcredfield'] = $totalarray['nbfield']; - } + $totalarray['totalcred'] += $objp->amount; + } + print "\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['totalcredfield'] = $totalarray['nbfield']; + } - // Balance before - if (!empty($arrayfields['balancebefore']['checked'])) - { - if ($mode_balance_ok) - { - if ($balancebefore >= 0) - { - print ''; - } else { - print ''; - } - } else { - print ''; - } - if (!$i) $totalarray['nbfield']++; - } - // Balance - if (!empty($arrayfields['balance']['checked'])) - { - if ($mode_balance_ok) - { - if ($balance >= 0) - { - print ''; - } else { - print ''; - } - } else { - print ''; - } - if (!$i) $totalarray['nbfield']++; - } + // Balance before + if (!empty($arrayfields['balancebefore']['checked'])) + { + if ($mode_balance_ok) + { + if ($balancebefore >= 0) + { + print ''; + } + else + { + print ''; + } + } + else + { + print ''; + } + if (!$i) $totalarray['nbfield']++; + } + // Balance + if (!empty($arrayfields['balance']['checked'])) + { + if ($mode_balance_ok) + { + if ($balance >= 0) + { + print ''; + } + else + { + print ''; + } + } + else + { + print ''; + } + if (!$i) $totalarray['nbfield']++; + } - if (!empty($arrayfields['b.num_releve']['checked'])) - { - print ''; - if (!$i) - { - $totalarray['nbfield']++; - $posconciliatecol = $totalarray['nbfield']; - } - } + if (!empty($arrayfields['b.num_releve']['checked'])) + { + print ''; + if (!$i) + { + $totalarray['nbfield']++; + $posconciliatecol = $totalarray['nbfield']; + } + } - if (!empty($arrayfields['b.conciliated']['checked'])) - { - print ''; - if (!$i) $totalarray['nbfield']++; - } + if (!empty($arrayfields['b.conciliated']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } - // Action edit/delete - print ''; - if (!$i) $totalarray['nbfield']++; + // Action edit/delete + print ''; + if (!$i) $totalarray['nbfield']++; - // Action column - print ''; - if (!$i) $totalarray['nbfield']++; + // Action column + print ''; + if (!$i) $totalarray['nbfield']++; print ""; @@ -1523,25 +1574,27 @@ if ($resql) // Show total line if (isset($totalarray['totaldebfield']) || isset($totalarray['totalcredfield'])) { - print ''; - $i = 0; - while ($i < $totalarray['nbfield']) - { - $i++; - if ($i == 1) - { - if ($num < $limit && empty($offset)) print ''; - else print ''; - } elseif ($totalarray['totaldebfield'] == $i) print ''; - elseif ($totalarray['totalcredfield'] == $i) print ''; - elseif ($i == $posconciliatecol) - { - print ''; - } else print ''; - } - print ''; + print ''; + $i = 0; + while ($i < $totalarray['nbfield']) + { + $i++; + if ($i == 1) + { + if ($num < $limit && empty($offset)) print ''; + else print ''; + } + elseif ($totalarray['totaldebfield'] == $i) print ''; + elseif ($totalarray['totalcredfield'] == $i) print ''; + elseif ($i == $posconciliatecol) + { + print ''; + } + else print ''; + } + print ''; } // If no record found @@ -1555,9 +1608,11 @@ if ($resql) print "
'; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print '    '; - $form->select_types_paiements(empty($search_type) ? '' : $search_type, 'search_type', '', 2, 1, 1, 0, 1, 'maxwidth100'); - print ''; + $form->select_types_paiements(empty($search_type) ? '' : $search_type, 'search_type', '', 2, 1, 1, 0, 1, 'maxwidth100'); + print ''; - $form->select_comptes($search_account, 'search_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''), 0, 'maxwidth100'); - print ''; + $form->select_comptes($search_account, 'search_account', 0, '', 1, ($id > 0 || !empty($ref) ? ' disabled="disabled"' : ''), 0, 'maxwidth100'); + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print $form->selectyesno('search_conciliated', $search_conciliated, 1, false, 1, 1); - print ''; + print $form->selectyesno('search_conciliated', $search_conciliated, 1, false, 1); + print ''; print ''; $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1); print $searchpicto; - print '
'; - print ' '; + // Output a line with start balance + if ($user->rights->banque->consolidate && $action == 'reconcile') + { + $tmpnbfieldbeforebalance = 0; + $tmpnbfieldafterbalance = 0; + $balancefieldfound = 0; + foreach ($arrayfields as $key => $val) + { + if ($key == 'balancebefore' || $key == 'balance') + { + $balancefieldfound++; + continue; + } + if (!empty($arrayfields[$key]['checked'])) + { + if (!$balancefieldfound) $tmpnbfieldbeforebalance++; + else $tmpnbfieldafterbalance++; + } + } + // Extra fields + $element = 'banktransaction'; + if (is_array($extrafields->attributes[$element]['label']) && count($extrafields->attributes[$element]['label'])) + { + foreach ($extrafields->attributes[$element]['label'] as $key => $val) + { + if (!empty($arrayfields["ef.".$key]['checked'])) + { + if (!empty($arrayfields[$key]['checked'])) + { + if (!$balancefieldfound) $tmpnbfieldbeforebalance++; + else $tmpnbfieldafterbalance++; + } + } + } + } + + print '
'; + print ' '; + print ''; + print price(price2num($balance, 'MT'), 1, $langs); + print ''; + print price(price2num($balance, 'MT'), 1, $langs); print ''; - if ($search_conciliated !== '0') { - print price(price2num($balance, 'MT'), 1, $langs); - } - print ''; - if ($search_conciliated !== '0') { - print price(price2num($balance, 'MT'), 1, $langs); - } - print ''; - print ''; - print ' '; - print ''; + print ''; + print ' '; + print ''; print ' '; print '
'; + print "rowid.'&save_lastsearch_values=1">'.img_object($langs->trans("ShowPayment").': '.$objp->rowid, 'account', 'class="classfortooltip"').' '.$objp->rowid."   "; + print '
"; - // Ref - if (!empty($arrayfields['b.rowid']['checked'])) - { - print ''; - print $banklinestatic->getNomUrl(1); - print '"; + // Add links after description + $links = $bankaccountstatic->get_url($objp->rowid); + $cachebankaccount = array(); + foreach ($links as $key=>$val) + { + print ''; + if ($links[$key]['type'] == 'withdraw') + { + $banktransferstatic->id = $links[$key]['url_id']; + $banktransferstatic->ref = $links[$key]['label']; + print ' '.$banktransferstatic->getNomUrl(0); + } + elseif ($links[$key]['type'] == 'payment') + { + $paymentstatic->id = $links[$key]['url_id']; + $paymentstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment + print ' '.$paymentstatic->getNomUrl(2); + } + elseif ($links[$key]['type'] == 'payment_supplier') + { + $paymentsupplierstatic->id = $links[$key]['url_id']; + $paymentsupplierstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment + print ' '.$paymentsupplierstatic->getNomUrl(2); + } + elseif ($links[$key]['type'] == 'payment_sc') + { + print ''; + print ' '.img_object($langs->trans('ShowPayment'), 'payment').' '; + //print $langs->trans("SocialContributionPayment"); + print ''; + } + elseif ($links[$key]['type'] == 'payment_vat') + { + $paymentvatstatic->id = $links[$key]['url_id']; + $paymentvatstatic->ref = $links[$key]['url_id']; + print ' '.$paymentvatstatic->getNomUrl(2); + } + elseif ($links[$key]['type'] == 'payment_salary') + { + $paymentsalstatic->id = $links[$key]['url_id']; + $paymentsalstatic->ref = $links[$key]['url_id']; + print ' '.$paymentsalstatic->getNomUrl(2); + } + elseif ($links[$key]['type'] == 'payment_loan') + { + print ''; + print ' '.img_object($langs->trans('ShowPayment'), 'payment').' '; + print ''; + } + elseif ($links[$key]['type'] == 'payment_donation') + { + print ''; + print ' '.img_object($langs->trans('ShowPayment'), 'payment').' '; + print ''; + } + elseif ($links[$key]['type'] == 'payment_expensereport') + { + $paymentexpensereportstatic->id = $links[$key]['url_id']; + $paymentexpensereportstatic->ref = $links[$key]['url_id']; + print ' '.$paymentexpensereportstatic->getNomUrl(2); + } + elseif ($links[$key]['type'] == 'payment_various') + { + $paymentvariousstatic->id = $links[$key]['url_id']; + $paymentvariousstatic->ref = $links[$key]['url_id']; + print ' '.$paymentvariousstatic->getNomUrl(2); + } + elseif ($links[$key]['type'] == 'banktransfert') + { + // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail. + if ($objp->amount > 0) + { + $banklinestatic->fetch($links[$key]['url_id']); + $bankstatic->id = $banklinestatic->fk_account; + $bankstatic->label = $banklinestatic->bank_account_ref; + print ' ('.$langs->trans("TransferFrom").' '; + print $bankstatic->getNomUrl(1, 'transactions'); + print ' '.$langs->trans("toward").' '; + $bankstatic->id = $objp->bankid; + $bankstatic->label = $objp->bankref; + print $bankstatic->getNomUrl(1, ''); + print ')'; + } + else + { + $bankstatic->id = $objp->bankid; + $bankstatic->label = $objp->bankref; + print ' ('.$langs->trans("TransferFrom").' '; + print $bankstatic->getNomUrl(1, ''); + print ' '.$langs->trans("toward").' '; + $banklinestatic->fetch($links[$key]['url_id']); + $bankstatic->id = $banklinestatic->fk_account; + $bankstatic->label = $banklinestatic->bank_account_ref; + print $bankstatic->getNomUrl(1, 'transactions'); + print ')'; + } + //var_dump($links); + } + elseif ($links[$key]['type'] == 'company') + { + } + elseif ($links[$key]['type'] == 'user') + { + } + elseif ($links[$key]['type'] == 'member') + { + } + elseif ($links[$key]['type'] == 'sc') + { + } + else + { + // Show link with label $links[$key]['label'] + if (!empty($objp->label) && !empty($links[$key]['label'])) print ' - '; + print ''; + if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) + { + // Label generique car entre parentheses. On l'affiche en le traduisant + if ($reg[1] == 'paiement') $reg[1] = 'Payment'; + print ' '.$langs->trans($reg[1]); + } + else + { + print ' '.$links[$key]['label']; + } + print ''; + } + } + print ''; + print ''.dol_print_date($db->jdate($objp->do), "day").""; + print ' '; + print ''; + print ''; + print img_edit_remove()." "; + print ''; + print img_edit_add().""; + print ''; + print "'; + print ''.dol_print_date($db->jdate($objp->dv), "day").""; + print ' '; + print ''; + print ''; + print img_edit_remove()." "; + print ''; + print img_edit_add().""; + print ''; + print "'; - print ''.dol_print_date($db->jdate($objp->do), "day").""; - print ' '; - print ''; - print ''; - print img_edit_remove()." "; - print ''; - print img_edit_add().""; - print ''; - print "'; + $labeltype = ($langs->trans("PaymentTypeShort".$objp->fk_type) != "PaymentTypeShort".$objp->fk_type) ? $langs->trans("PaymentTypeShort".$objp->fk_type) : $langs->getLabelFromKey($db, $objp->fk_type, 'c_paiement', 'code', 'libelle', '', 1); + if ($labeltype == 'SOLD') print ' '; //$langs->trans("InitialBankBalance"); + else print $labeltype; + print "'; - print ''.dol_print_date($db->jdate($objp->dv), "day").""; - print ' '; - print ''; - print ''; - print img_edit_remove()." "; - print ''; - print img_edit_add().""; - print ''; - print "'; - $labeltype = ($langs->trans("PaymentTypeShort".$objp->fk_type) != "PaymentTypeShort".$objp->fk_type) ? $langs->trans("PaymentTypeShort".$objp->fk_type) : $langs->getLabelFromKey($db, $objp->fk_type, 'c_paiement', 'code', 'libelle', '', 1); - if ($labeltype == 'SOLD') print ' '; //$langs->trans("InitialBankBalance"); - else print $labeltype; - print "'.($objp->num_chq ? $objp->num_chq : "")."'.($objp->num_chq ? $objp->num_chq : "")."'; + if (!empty($arrayfields['bu.label']['checked'])) + { + print ''; if ($objp->url_id) { $companystatic->id = $objp->url_id; @@ -1359,161 +1396,175 @@ if ($resql) $companystatic->code_compta = $objp->code_compta; $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur; print $companystatic->getNomUrl(1); - } else { + } + else + { print ' '; } print ''; + // Bank account + if (!empty($arrayfields['ba.ref']['checked'])) + { + print ''; print $bankaccount->getNomUrl(1); print "'; - if ($objp->amount < 0) - { - print price($objp->amount * -1); - $totalarray['totaldeb'] += $objp->amount; - } - print "'; + if ($objp->amount < 0) + { + print price($objp->amount * -1); + $totalarray['totaldeb'] += $objp->amount; + } + print "'; - if ($objp->amount > 0) - { + // Credit + if (!empty($arrayfields['b.credit']['checked'])) + { + print ''; + if ($objp->amount > 0) + { print price($objp->amount); - $totalarray['totalcred'] += $objp->amount; - } - print " '.price($balancebefore).' '.price($balancebefore).'- '.price($balance).' '.price($balance).'- '.price($balancebefore).' '.price($balancebefore).'- '.price($balance).' '.price($balance).'-'; - // Transaction reconciliated or edit link - if ($bankaccount->canBeConciliated() > 0) - { - if ($objp->num_releve) - { - print ''.$objp->num_releve.''; - } - if (!$objp->conciliated && $action == 'reconcile') - { - if ($objp->num_releve) print ' '; - print 'rowid]) ? ' checked' : '').'>'; - } - } - print ''; + // Transaction reconciliated or edit link + if ($bankaccount->canBeConciliated() > 0) + { + if ($objp->num_releve) + { + print ''.$objp->num_releve.''; + } + if (!$objp->conciliated && $action == 'reconcile') + { + if ($objp->num_releve) print ' '; + print 'rowid]) ? ' checked' : '').'>'; + } + } + print ''; - print $objp->conciliated ? $langs->trans("Yes") : $langs->trans("No"); - print ''; + print $objp->conciliated ? $langs->trans("Yes") : $langs->trans("No"); + print ''; - // Transaction reconciliated or edit link - if ($objp->conciliated && $bankaccount->canBeConciliated() > 0) // If line not conciliated and account can be conciliated - { - print ''; - print img_edit(); - print ''; - } else { - if ($user->rights->banque->modifier || $user->rights->banque->consolidate) - { - print ''; - print img_edit(); - print ''; - } else { - print ''; - print img_view(); - print ''; - } - if ($bankaccount->canBeConciliated() > 0 && empty($objp->conciliated)) - { - if ($db->jdate($objp->dv) < ($now - $conf->bank->rappro->warning_delay)) - { - print ' '.img_warning($langs->trans("ReconciliationLate")); - } - } - if ($user->rights->banque->modifier) - { - print 'rowid.'&id='.$objp->bankid.'&page='.$page.'">'; - print img_delete('', 'class="marginleftonly"'); - print ''; - } - } - print ''; + // Transaction reconciliated or edit link + if ($objp->conciliated && $bankaccount->canBeConciliated() > 0) // If line not conciliated and account can be conciliated + { + print ''; + print img_edit(); + print ''; + } + else + { + if ($user->rights->banque->modifier || $user->rights->banque->consolidate) + { + print ''; + print img_edit(); + print ''; + } + else + { + print ''; + print img_view(); + print ''; + } + if ($bankaccount->canBeConciliated() > 0 && empty($objp->conciliated)) + { + if ($db->jdate($objp->dv) < ($now - $conf->bank->rappro->warning_delay)) + { + print ' '.img_warning($langs->trans("ReconciliationLate")); + } + } + if ($user->rights->banque->modifier) + { + print 'rowid.'&id='.$objp->bankid.'&page='.$page.'">'; + print img_delete('', 'class="marginleftonly"'); + print ''; + } + } + print ''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { - $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) $selected = 1; - print ''; - } - print ''; + if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + { + $selected = 0; + if (in_array($obj->rowid, $arrayofselected)) $selected = 1; + print ''; + } + print '
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.price(-1 * $totalarray['totaldeb']).''.price($totalarray['totalcred']).''; - if ($user->rights->banque->consolidate && $action == 'reconcile') print ''; - print '
'.$langs->trans("Total").''.$langs->trans("Totalforthispage").''.price(-1 * $totalarray['totaldeb']).''.price($totalarray['totalcred']).''; + if ($user->rights->banque->consolidate && $action == 'reconcile') print ''; + print '
"; print "
"; - print ''; + print ''; $db->free($resql); -} else { +} +else +{ dol_print_error($db); } diff --git a/htdocs/compta/bank/line.php b/htdocs/compta/bank/line.php index 467f6b7b78b..6a5a94f3a5e 100644 --- a/htdocs/compta/bank/line.php +++ b/htdocs/compta/bank/line.php @@ -8,6 +8,7 @@ * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2016 Marcos García * Copyright (C) 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 @@ -355,6 +356,11 @@ if ($result) print img_object($langs->trans('SocialContribution'), 'bill').' '; print $langs->trans("SocialContribution").($links[$key]['label'] ? ' - '.$links[$key]['label'] : ''); print ''; + } elseif ($links[$key]['type'] == 'salary') { + print ''; + print img_object($langs->trans('Salary'), 'bill').' '; + print $langs->trans("Salary").($links[$key]['label'] ? ' - '.$links[$key]['label'] : ''); + print ''; } elseif ($links[$key]['type'] == 'payment_sc') { print ''; print img_object($langs->trans('Payment'), 'payment').' '; @@ -366,7 +372,7 @@ if ($result) print $langs->trans("VATPayment"); print ''; } elseif ($links[$key]['type'] == 'payment_salary') { - print ''; + print ''; print img_object($langs->trans('PaymentSalary'), 'payment').' '; print $langs->trans("SalaryPayment"); print ''; diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index 3588dced3f4..ad0befe1c05 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -6,6 +6,7 @@ * Copyright (C) 2011-2014 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2019 Nicolas ZABOURI + * 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 @@ -31,7 +32,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php'; -require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; @@ -74,7 +75,7 @@ if (!$sortorder) $sortorder = "DESC"; $tva_static = new Tva($db); $socialcontrib = new ChargeSociales($db); $payment_sc_static = new PaymentSocialContribution($db); -$sal_static = new PaymentSalary($db); +$sal_static = new Salary($db); $accountstatic = new Account($db); llxHeader('', $langs->trans("SpecialExpensesArea")); @@ -441,7 +442,7 @@ while ($j < $numlt) /* if (!empty($conf->salaries->enabled) && !empty($user->rights->salaries->read)) { - $sal = new PaymentSalary($db); + $sal = new Salary($db); print "
"; diff --git a/htdocs/compta/sociales/payments.php b/htdocs/compta/sociales/payments.php index 7432702bb34..be83a204e71 100644 --- a/htdocs/compta/sociales/payments.php +++ b/htdocs/compta/sociales/payments.php @@ -6,6 +6,7 @@ * Copyright (C) 2011-2014 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2019 Nicolas ZABOURI + * 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 @@ -31,7 +32,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php'; -require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php'; @@ -89,7 +90,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $tva_static = new Tva($db); $socialcontrib = new ChargeSociales($db); $payment_sc_static = new PaymentSocialContribution($db); -$sal_static = new PaymentSalary($db); +$sal_static = new Salary($db); $accountstatic = new Account($db); $formsocialcontrib = new FormSocialContrib($db); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 159898f7256..83c5f2c9007 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2071,6 +2071,7 @@ abstract class CommonObject $fieldname = 'fk_mode_reglement'; if ($this->element == 'societe') $fieldname = 'mode_reglement'; if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; + if (get_class($this) == 'Salary') $fieldname = 'fk_typepayment'; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql .= ' SET '.$fieldname.' = '.(($id > 0 || $id == '0') ? $id : 'NULL'); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f4666c37dc8..3597884b2b0 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -16,6 +16,7 @@ * Copyright (C) 2018-2020 Frédéric France * Copyright (C) 2019 Thibault Foucart * Copyright (C) 2020 Open-Dsi + * 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 @@ -1771,7 +1772,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi } else { $morehtmlstatus .= ''.$object->getLibStatut(6, 1).''; } - } elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier', 'chargesociales', 'loan'))) { + } elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier', 'chargesociales', 'loan', 'salary'))) { $tmptxt = $object->getLibStatut(6, $object->totalpaye); if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) $tmptxt = $object->getLibStatut(5, $object->totalpaye); $morehtmlstatus .= $tmptxt; diff --git a/htdocs/core/lib/salaries.lib.php b/htdocs/core/lib/salaries.lib.php index f4662f43991..4ecf5aa630a 100644 --- a/htdocs/core/lib/salaries.lib.php +++ b/htdocs/core/lib/salaries.lib.php @@ -2,6 +2,7 @@ /** * Copyright (C) 2015 Charlie BENKE * Copyright (C) 2019 Alexandre Spangaro + * 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 @@ -33,7 +34,7 @@ function salaries_prepare_head($object) $head = array(); $head[$h][0] = DOL_URL_ROOT.'/salaries/card.php?id='.$object->id; - $head[$h][1] = $langs->trans("SalaryPayment"); + $head[$h][1] = $langs->trans("Salary"); $head[$h][2] = 'card'; $h++; diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index f1141140973..0e7d46bd46f 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1142,8 +1142,9 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM $langs->load("salaries"); $newmenu->add("/salaries/list.php?leftmenu=tax_salary&mainmenu=billing", $langs->trans("Salaries"), 0, $user->rights->salaries->read, '', $mainmenu, 'tax_salary', 0, '', '', '', img_picto('', 'salary', 'class="paddingright pictofixedwidth"')); if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_salary/i', $leftmenu)) { - $newmenu->add("/salaries/card.php?leftmenu=tax_salary&action=create", $langs->trans("NewPayment"), 1, $user->rights->salaries->write); - $newmenu->add("/salaries/list.php?leftmenu=tax_salary", $langs->trans("Payments"), 1, $user->rights->salaries->read); + $newmenu->add("/salaries/card.php?leftmenu=tax_salary&action=create", $langs->trans("New"), 1, $user->rights->salaries->write); + $newmenu->add("/salaries/list.php?leftmenu=tax_salary", $langs->trans("List"), 1, $user->rights->salaries->read); + $newmenu->add("/salaries/payments.php?leftmenu=tax_salary", $langs->trans("Payments"), 1, $user->rights->salaries->read); $newmenu->add("/salaries/stats/index.php?leftmenu=tax_salary", $langs->trans("Statistics"), 1, $user->rights->salaries->read); } } diff --git a/htdocs/install/mysql/tables/llx_payment_salary.sql b/htdocs/install/mysql/tables/llx_payment_salary.sql index d6ad2ffcfed..9e7400f0c0d 100644 --- a/htdocs/install/mysql/tables/llx_payment_salary.sql +++ b/htdocs/install/mysql/tables/llx_payment_salary.sql @@ -1,5 +1,6 @@ -- =================================================================== --- Copyright (C) 2011-2018 Alexandre Spangaro +-- Copyright (C) 2004 Laurent Destailleur +-- 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 @@ -19,23 +20,16 @@ create table llx_payment_salary ( rowid integer AUTO_INCREMENT PRIMARY KEY, - ref varchar(30) NULL, -- payment reference number (currently NULL because there is no numbering manager yet) - tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - datec datetime, -- Create date - fk_user integer NOT NULL, - datep date, -- payment date - datev date, -- value date (this field should not be here, only into bank tables) - salary double(24,8), -- salary of user when payment was done - amount double(24,8) NOT NULL DEFAULT 0, - fk_projet integer DEFAULT NULL, - fk_typepayment integer NOT NULL, - num_payment varchar(50), -- num cheque or other - label varchar(255), - datesp date, -- date start period - dateep date, -- date end period - entity integer DEFAULT 1 NOT NULL, -- multi company id + fk_salary integer, + datec datetime, -- date de creation + tms timestamp, + datep datetime, -- payment date + amount double(24,8) DEFAULT 0, + fk_typepaiement integer NOT NULL, + num_paiement varchar(50), note text, - fk_bank integer, - fk_user_author integer, -- user creating - fk_user_modif integer -- user making last change + fk_bank integer NOT NULL, + fk_user_creat integer, -- creation user + fk_user_modif integer -- last modification user + )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_payment_salary.key.sql b/htdocs/install/mysql/tables/llx_salary.key.sql similarity index 63% rename from htdocs/install/mysql/tables/llx_payment_salary.key.sql rename to htdocs/install/mysql/tables/llx_salary.key.sql index 946cd1a08ff..d3e51cb99ff 100644 --- a/htdocs/install/mysql/tables/llx_payment_salary.key.sql +++ b/htdocs/install/mysql/tables/llx_salary.key.sql @@ -1,5 +1,6 @@ -- ============================================================================ -- Copyright (C) 2015 Laurent Destailleur +-- 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 @@ -17,11 +18,11 @@ -- ============================================================================ -ALTER TABLE llx_payment_salary ADD INDEX idx_payment_salary_ref (num_payment); -ALTER TABLE llx_payment_salary ADD INDEX idx_payment_salary_user (fk_user, entity); -ALTER TABLE llx_payment_salary ADD INDEX idx_payment_salary_datep (datep); -ALTER TABLE llx_payment_salary ADD INDEX idx_payment_salary_datesp (datesp); -ALTER TABLE llx_payment_salary ADD INDEX idx_payment_salary_dateep (dateep); +ALTER TABLE llx_salary ADD INDEX idx_salary_ref (num_payment); +ALTER TABLE llx_salary ADD INDEX idx_salary_user (fk_user, entity); +ALTER TABLE llx_salary ADD INDEX idx_salary_datep (datep); +ALTER TABLE llx_salary ADD INDEX idx_salary_datesp (datesp); +ALTER TABLE llx_salary ADD INDEX idx_salary_dateep (dateep); -ALTER TABLE llx_payment_salary ADD CONSTRAINT fk_payment_salary_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid); +ALTER TABLE llx_salary ADD CONSTRAINT fk_salary_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid); diff --git a/htdocs/install/mysql/tables/llx_salary.sql b/htdocs/install/mysql/tables/llx_salary.sql new file mode 100644 index 00000000000..af4b869d9bf --- /dev/null +++ b/htdocs/install/mysql/tables/llx_salary.sql @@ -0,0 +1,44 @@ +-- =================================================================== +-- Copyright (C) 2011-2018 Alexandre Spangaro +-- 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 . +-- +-- =================================================================== + +create table llx_salary +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + ref varchar(30) NULL, -- payment reference number (currently NULL because there is no numbering manager yet) + tms timestamp, + datec datetime, -- Create date + fk_user integer NOT NULL, + datep date, -- payment date + datev date, -- value date (this field should not be here, only into bank tables) + salary double(24,8), -- salary of user when payment was done + amount double(24,8) NOT NULL DEFAULT 0, + fk_projet integer DEFAULT NULL, + fk_typepayment integer NOT NULL, + num_payment varchar(50), -- num cheque or other + label varchar(255), + datesp date, -- date start period + dateep date, -- date end period + entity integer DEFAULT 1 NOT NULL, -- multi company id + note text, + fk_bank integer, + paye smallint default 0 NOT NULL, + fk_account integer, + fk_user_author integer, -- user creating + fk_user_modif integer -- user making last change +)ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_payment_salary_extrafields.key.sql b/htdocs/install/mysql/tables/llx_salary_extrafields.key.sql similarity index 84% rename from htdocs/install/mysql/tables/llx_payment_salary_extrafields.key.sql rename to htdocs/install/mysql/tables/llx_salary_extrafields.key.sql index 9231351a749..2aa8c9a4cad 100644 --- a/htdocs/install/mysql/tables/llx_payment_salary_extrafields.key.sql +++ b/htdocs/install/mysql/tables/llx_salary_extrafields.key.sql @@ -1,5 +1,6 @@ -- =================================================================== -- Copyright (C) 2019 Alexandre Spangaro +-- 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 @@ -17,4 +18,4 @@ -- =================================================================== -ALTER TABLE llx_payment_salary_extrafields ADD INDEX idx_payment_salary_extrafields (fk_object); +ALTER TABLE llx_salary_extrafields ADD INDEX idx_salary_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_payment_salary_extrafields.sql b/htdocs/install/mysql/tables/llx_salary_extrafields.sql similarity index 90% rename from htdocs/install/mysql/tables/llx_payment_salary_extrafields.sql rename to htdocs/install/mysql/tables/llx_salary_extrafields.sql index 5f15918ef18..2728ee55f2f 100644 --- a/htdocs/install/mysql/tables/llx_payment_salary_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_salary_extrafields.sql @@ -1,5 +1,6 @@ -- =================================================================== -- Copyright (C) 2019 Alexandre Spangaro +-- 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 @@ -16,7 +17,7 @@ -- -- =================================================================== -create table llx_payment_salary_extrafields +create table llx_salary_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 88f4c59a28d..006dc0c823e 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -494,12 +494,14 @@ Cash=Cash Reported=Delayed DisabledBecausePayments=Not possible since there are some payments CantRemovePaymentWithOneInvoicePaid=Can't remove payment since there is at least one invoice classified paid +CantRemovePaymentSalaryPaid=Can't remove payment since salary is classified paid ExpectedToPay=Expected payment CantRemoveConciliatedPayment=Can't remove reconciled payment PayedByThisPayment=Paid by this payment ClosePaidInvoicesAutomatically=Classify automatically all standard, down payment or replacement invoices as "Paid" when payment is done entirely. ClosePaidCreditNotesAutomatically=Classify automatically all credit notes as "Paid" when refund is done entirely. ClosePaidContributionsAutomatically=Classify automatically all social or fiscal contributions as "Paid" when payment is done entirely. +ClosePaidSalaryAutomatically=Classify automatically salary as "Paid" when payment is done entirely. AllCompletelyPayedInvoiceWillBeClosed=All invoices with no remainder to pay will be automatically closed with status "Paid". ToMakePayment=Pay ToMakePaymentBack=Pay back diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index 1afeb6e3727..4bd51773226 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -134,9 +134,13 @@ NoWaitingChecks=No checks awaiting deposit. DateChequeReceived=Check reception date NbOfCheques=No. of checks PaySocialContribution=Pay a social/fiscal tax +ConfirmPaySalary=Pay a salary card ConfirmPaySocialContribution=Are you sure you want to classify this social or fiscal tax as paid? +ConfirmPaySalary=Are you sure you want to classify this salary card as paid? DeleteSocialContribution=Delete a social or fiscal tax payment +DeleteSalary=Delete a salary card ConfirmDeleteSocialContribution=Are you sure you want to delete this social/fiscal tax payment? +ConfirmDeleteSalary=Are you sure you want to delete this salary? ExportDataset_tax_1=Social and fiscal taxes and payments CalcModeVATDebt=Mode %sVAT on commitment accounting%s. CalcModeVATEngagement=Mode %sVAT on incomes-expenses%s. @@ -235,6 +239,7 @@ ACCOUNTING_ACCOUNT_CUSTOMER_Desc=The dedicated accounting account defined on thi ACCOUNTING_ACCOUNT_SUPPLIER=Accounting account used for vendor third parties ACCOUNTING_ACCOUNT_SUPPLIER_Desc=The dedicated accounting account defined on third party card will be used for Subledger accounting only. This one will be used for General Ledger and as default value of Subledger accounting if dedicated vendor accounting account on third party is not defined. ConfirmCloneTax=Confirm the clone of a social/fiscal tax +ConfirmCloneSalary=Confirm the clone of a salary CloneTaxForNextMonth=Clone it for next month SimpleReport=Simple report AddExtraReport=Extra reports (add foreign and national customer report) diff --git a/htdocs/langs/en_US/salaries.lang b/htdocs/langs/en_US/salaries.lang index 7c3c08a65bd..971759ff2ce 100644 --- a/htdocs/langs/en_US/salaries.lang +++ b/htdocs/langs/en_US/salaries.lang @@ -4,7 +4,7 @@ SALARIES_ACCOUNTING_ACCOUNT_PAYMENT_Desc=The dedicated accounting account define SALARIES_ACCOUNTING_ACCOUNT_CHARGE=Accounting account by default for wage payments Salary=Salary Salaries=Salaries -NewSalaryPayment=New salary payment +NewSalaryPayment=New salary card AddSalaryPayment=Add salary payment SalaryPayment=Salary payment SalariesPayments=Salaries payments diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 6802d0e84a9..08634cf6def 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -6,6 +6,7 @@ * Copyright (C) 2015-2019 Alexandre Spangaro * Copyright (C) 2015 Marcos García * Copyright (C) 2016 Josep Lluís Amador + * 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 @@ -53,7 +54,7 @@ if (!empty($conf->loan->enabled)) require_once DOL_DOCUMENT_ROOT.'/loan/class/ if (!empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; if (!empty($conf->tax->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php'; -if (!empty($conf->salaries->enabled)) require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +if (!empty($conf->salaries->enabled)) require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; if (!empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; if (!empty($conf->mrp->enabled)) require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php'; @@ -486,7 +487,7 @@ $listofreferent = array( 'salaries'=>array( 'name'=>"Salaries", 'title'=>"ListSalariesAssociatedProject", - 'class'=>'PaymentSalary', + 'class'=>'Salary', 'table'=>'payment_salary', 'datefieldname'=>'datev', 'margin'=>'minus', diff --git a/htdocs/salaries/card.php b/htdocs/salaries/card.php index 2fc71bec099..8e1615f599f 100644 --- a/htdocs/salaries/card.php +++ b/htdocs/salaries/card.php @@ -4,6 +4,7 @@ * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2015 Charlie BENKE * Copyright (C) 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 @@ -27,6 +28,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.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'; require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php'; @@ -38,7 +40,7 @@ if (!empty($conf->projet->enabled)) } // Load translation files required by the page -$langs->loadLangs(array("compta", "banks", "bills", "users", "salaries", "hrm")); +$langs->loadLangs(array("compta", "banks", "bills", "users", "salaries", "hrm", "trips")); if (!empty($conf->projet->enabled)) $langs->load("projects"); $id = GETPOST("id", 'int'); @@ -46,18 +48,21 @@ $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel', 'aZ09'); $accountid = GETPOST('accountid', 'int') > 0 ? GETPOST('accountid', 'int') : 0; $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int')); +$confirm = GETPOST('confirm'); +$auto_create_paiement = GETPOST("auto_create_paiement", "int"); $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int')); $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int')); $datesp = dol_mktime(12, 0, 0, GETPOST("datespmonth", 'int'), GETPOST("datespday", 'int'), GETPOST("datespyear", 'int')); $dateep = dol_mktime(12, 0, 0, GETPOST("dateepmonth", 'int'), GETPOST("dateepday", 'int'), GETPOST("dateepyear", 'int')); +$label = GETPOST('label'); // Security check $socid = GETPOST("socid", "int"); if ($user->socid) $socid = $user->socid; $result = restrictedArea($user, 'salaries', '', '', ''); -$object = new PaymentSalary($db); +$object = new Salary($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels @@ -84,19 +89,66 @@ if ($action == 'classin' && $user->rights->banque->modifier) $object->setProject($projectid); } +// set label +if ($action == 'setlabel' && $user->rights->salaries->write) { + $object->fetch($id); + $object->label = $label; + $object->update($user); +} + +// Classify paid +if ($action == 'confirm_paid' && $user->rights->salaries->write && $confirm == 'yes') +{ + $object->fetch($id); + $result = $object->set_paid($user); +} + +// Reopen +if ($action == 'reopen' && $user->rights->salaries->write) { + $result = $object->fetch($id); + if ($object->paye) + { + $result = $object->set_unpaid($user); + if ($result > 0) + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); + exit(); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } +} + +// payment mode +if ($action == 'setmode' && $user->rights->salaries->write) { + $object->fetch($id); + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); +} + +// bank account +if ($action == 'setbankaccount' && $user->rights->salaries->write) { + $object->fetch($id); + $result = $object->setBankAccount(GETPOST('fk_account', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + if ($action == 'add' && empty($cancel)) { $error = 0; if (empty($datev)) $datev = $datep; - $type_payment = dol_getIdFromCode($db, GETPOST("paymenttype", 'alpha'), 'c_paiement', 'code', 'id', 1); + $type_payment = GETPOST("paymenttype", 'alpha'); $object->accountid = GETPOST("accountid", 'int') > 0 ? GETPOST("accountid", "int") : 0; $object->fk_user = GETPOST("fk_user", 'int') > 0 ? GETPOST("fk_user", "int") : 0; $object->datev = $datev; $object->datep = $datep; - $object->amount = price2num(GETPOST("amount", 'alpha')); + $object->amount = $amount = price2num(GETPOST("amount", 'alpha')); $object->label = GETPOST("label", 'alphanohtml'); $object->datesp = $datesp; $object->dateep = $dateep; @@ -115,7 +167,11 @@ if ($action == 'add' && empty($cancel)) $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; - if (empty($datep) || empty($datev) || empty($datesp) || empty($dateep)) + if (!empty($auto_create_paiement) && empty($datep)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DATE_PAIEMENT")), null, 'errors'); + $error++; + } + if (empty($datesp) || empty($dateep)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $error++; @@ -125,7 +181,7 @@ if ($action == 'add' && empty($cancel)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Employee")), null, 'errors'); $error++; } - if (empty($type_payment) || $type_payment < 0) + if (!empty($auto_create_paiement) && (empty($type_payment) || $type_payment < 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors'); $error++; @@ -135,7 +191,7 @@ if ($action == 'add' && empty($cancel)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors'); $error++; } - if (!empty($conf->banque->enabled) && !$object->accountid > 0) + if (!empty($conf->banque->enabled) && !empty($auto_create_paiement) && !$object->accountid > 0) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors'); $error++; @@ -143,65 +199,171 @@ if ($action == 'add' && empty($cancel)) if (!$error) { - $db->begin(); - $ret = $object->create($user); - if ($ret > 0) + if ($ret < 0) $error++; + if (!empty($auto_create_paiement) && !$error) { - $db->commit(); + $db->begin(); + // Create a line of payments + $paiement = new PaymentSalary($db); + $paiement->chid = $object->id; + $paiement->datepaye = $datep; + $paiement->datev = $datev; + $paiement->amounts = array($object->id=>$amount); // Tableau de montant + $paiement->paiementtype = $type_payment; + $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); + $paiement->note = GETPOST("note", 'none'); + if (!$error) + { + $paymentid = $paiement->create($user, (int) GETPOST('closepaidsalary')); + 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'); + } + } + + if (!$error) + { + $db->commit(); + } + else { + $db->rollback(); + } + } + + if(empty($error)) { if (GETPOST('saveandnew', 'alpha')) { setEventMessages($langs->trans("RecordSaved"), '', 'mesgs'); - header("Location: card.php?action=create&fk_project=".urlencode($projectid)."&accountid=".urlencode($accountid).'&paymenttype='.urlencode(GETPOST('paymenttype', 'az09')).'&datepday='.GETPOST("datepday", 'int').'&datepmonth='.GETPOST("datepmonth", 'int').'&datepyear='.GETPOST("datepyear", 'int')); + header("Location: card.php?action=create&fk_project=" . urlencode($projectid) . "&accountid=" . urlencode($accountid) . '&paymenttype=' . urlencode(GETPOST('paymenttype', 'az09')) . '&datepday=' . GETPOST("datepday", 'int') . '&datepmonth=' . GETPOST("datepmonth", 'int') . '&datepyear=' . GETPOST("datepyear", 'int')); exit; } else { - header("Location: list.php"); + header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $object->id); exit; } - } else { - $db->rollback(); - setEventMessages($object->error, $object->errors, 'errors'); - $action = "create"; } + } $action = 'create'; } -if ($action == 'delete') +if ($action == 'confirm_delete') { $result = $object->fetch($id); + $totalpaye = $object->getSommePaiement(); - if ($object->rappro == 0) + if (empty($totalpaye)) { $db->begin(); $ret = $object->delete($user); if ($ret > 0) { - if ($object->fk_bank) - { - $accountline = new AccountLine($db); - $result = $accountline->fetch($object->fk_bank); - if ($result > 0) $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing) - } - - if ($result >= 0) - { - $db->commit(); - header("Location: ".DOL_URL_ROOT.'/salaries/list.php'); - exit; - } else { - $object->error = $accountline->error; - $db->rollback(); - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { + $db->commit(); + header("Location: ".DOL_URL_ROOT.'/salaries/list.php'); + exit; + } + else { $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } - } else { - setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors'); + } + else { + setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors'); + } +} + + +if ($action == 'update' && !$_POST["cancel"] && $user->rights->salaries->write) +{ + $amount = price2num(GETPOST('amount')); + + if (empty($amount)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); + $action = 'edit'; + } + elseif (!is_numeric($amount)) + { + setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors'); + $action = 'create'; + } + else { + $result = $object->fetch($id); + + $object->amount = price2num($amount); + $object->datesp = price2num($datesp); + $object->dateep = price2num($dateep); + + $result = $object->update($user); + if ($result <= 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } +} + +if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; } + +if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->salaries->write)) +{ + $db->begin(); + + $originalId = $id; + + $object->fetch($id); + + if ($object->id > 0) + { + $object->paye = 0; + $object->id = $object->ref = null; + + if (GETPOST('clone_label', 'alphanohtml')) { + $object->label = GETPOST('clone_label', 'alphanohtml'); + } + else { + $object->label = $langs->trans("CopyOf").' '.$object->label; + } + + $newdatestart = dol_mktime(0, 0, 0, GETPOST('clone_date_startmonth', 'int'), GETPOST('clone_date_startday', 'int'), GETPOST('clone_date_startyear', 'int')); + $newdateend = dol_mktime(0, 0, 0, GETPOST('clone_date_endmonth', 'int'), GETPOST('clone_date_endday', 'int'), GETPOST('clone_date_endyear', 'int')); + + if ($newdatestart) $object->datesp = $newdatestart; + if ($newdateend) $object->dateep = $newdateend; + + //if ($object->check()) { + $id = $object->create($user); + if ($id > 0) + { + $db->commit(); + $db->close(); + + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else { + $id = $originalId; + $db->rollback(); + + setEventMessages($object->error, $object->errors, 'errors'); + } + //} + } + else { + $db->rollback(); + dol_print_error($db, $object->error); } } @@ -210,14 +372,14 @@ if ($action == 'delete') * View */ -llxHeader("", $langs->trans("SalaryPayment")); +llxHeader("", $langs->trans("Salary")); $form = new Form($db); if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db); if ($id) { - $object = new PaymentSalary($db); + $object = new Salary($db); $result = $object->fetch($id); if ($result <= 0) { @@ -258,22 +420,48 @@ if ($action == 'create') print load_fiche_titre($langs->trans("NewSalaryPayment"), '', 'salary'); + if (!empty($conf->use_javascript_ajax)) + { + print "\n".''."\n"; + } + print dol_get_fiche_head('', ''); print ''; - // Date payment - print ''; - - // Date value for bank - print ''; - // Employee print ''; @@ -320,11 +508,27 @@ if ($action == 'create') $form->select_types_paiements(GETPOST("paymenttype", 'aZ09'), "paymenttype", '', 2); print ''; + // Auto create payment + print ''; + print ''."\n"; + + // Date payment + print ''; + + // Date value for bank + print ''; + // Number if (!empty($conf->banque->enabled)) { // Number - print ''; print ''."\n"; @@ -340,6 +544,17 @@ if ($action == 'create') print ''; } + // Comments + print ''; + print ''; + print ''; + print ''; + + // Bouton Save payment + print ''; + // Other attributes $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -375,6 +590,37 @@ if ($id) { $head = salaries_prepare_head($object); + if ($action === 'clone') + { + $formquestion = array( + array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label), + ); + + //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1); + $formquestion[] = array('type' => 'date', 'name' => 'clone_date_start', 'label' => $langs->trans("DateStart"), 'value' => -1); + $formquestion[] = array('type' => 'date', 'name' => 'clone_date_end', 'label' => $langs->trans("DateEnd"), 'value' => -1); + + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneSalary', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240); + } + + if ($action == 'paid') + { + $text = $langs->trans('ConfirmPaySalary'); + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySalary'), $text, "confirm_paid", '', '', 2); + } + + if ($action == 'delete') + { + $text = $langs->trans('ConfirmDeleteSalary'); + print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSalary'), $text, 'confirm_delete', '', '', 2); + } + + if ($action == 'edit') + { + print "id&action=update\" method=\"post\">"; + print ''; + } + print dol_get_fiche_head($head, 'card', $langs->trans("SalaryPayment"), -1, 'salary'); $linkback = ''.$langs->trans("BackToList").''; @@ -418,52 +664,113 @@ if ($id) } } } + + // Label + if ($action != 'editlabel') { + $morehtmlref .= '
' . $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1); + $morehtmlref .= $object->label; + } else { + $morehtmlref .= '
'.$langs->trans('Label').' : '; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= ''; + } + + + $morehtmlref .= ''; + $totalpaye = $object->getSommePaiement(); + $object->totalpaye = $totalpaye; + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', ''); print '
'; + print '
'; print '
'; print '
'; - print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).''; - print $form->selectDate((empty($datep) ? '' : $datep), "datep", 0, 0, 0, 'add', 1, 1); - print '
'; - print $form->editfieldkey('DateValue', 'datev', '', $object, 0).''; - print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1); - print '
'; print $form->editfieldkey('Employee', 'fk_user', '', $object, 0, 'string', '', 1).''; @@ -308,7 +496,7 @@ if ($action == 'create') // Bank if (!empty($conf->banque->enabled)) { - print '
'; + print '
'; print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).''; $form->select_comptes($accountid, "accountid", 0, '', 1); // Affiche liste des comptes courant print '
'.$langs->trans('AutomaticCreationPayment').'
'; + print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).''; + print $form->selectDate((empty($datep) ? '' : $datep), "datep", 0, 0, 0, 'add', 1, 1); + print '
'; + print $form->editfieldkey('DateValue', 'datev', '', $object, 0).''; + print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1); + print '
'.$langs->trans("Comments").'
'; + print $langs->trans("ClosePaidSalaryAutomatically"); + print '
'; - // Label - print ''; + if ($action == 'edit') + { + print '"; - print ""; - print ''; + } else { + print ""; + print ''; + } - print ''; - print ""; + if ($action == 'edit') + { + print '"; + + } else { + print ""; + print ''; + } + + /*print ""; print ''; print '';*/ + + if ($action == 'edit') { + print ''; + } else { + print ''; + } + + // Mode of payment + print ''; - print ''; - + // Bank Account if (!empty($conf->banque->enabled)) { - if ($object->fk_account > 0) - { - $bankline = new AccountLine($db); - $bankline->fetch($object->fk_bank); - - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; } // Other attributes @@ -473,22 +780,182 @@ if ($id) print ''; + print '
'; + print '
'; + + $nbcols = 3; + if (!empty($conf->banque->enabled)) { + $nbcols++; + } + + /* + * Payments + */ + $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,"; + $sql .= " c.code as type_code,c.libelle as paiement_type,"; + $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.currency_code as bacurrency_code, ba.fk_accountancy_journal'; + $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p"; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id"; + $sql .= ", ".MAIN_DB_PREFIX."salary as salaire"; + $sql .= " WHERE p.fk_salary = ".$id; + $sql .= " AND p.fk_salary = salaire.rowid"; + $sql .= " AND salaire.entity IN (".getEntity('tax').")"; + $sql .= " ORDER BY dp DESC"; + + //print $sql; + $resql = $db->query($sql); + if ($resql) + { + $totalpaye = 0; + + $num = $db->num_rows($resql); + $i = 0; $total = 0; + + print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table + print '
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("DateStartPeriod").""; + print $form->selectDate($object->datesp, 'datesp', 0, 0, 0, 'datesp', 1); + print "
'.$langs->trans("DateStartPeriod").''; - print dol_print_date($object->datesp, 'day'); - print '
' . $langs->trans("DateStartPeriod") . ''; + print dol_print_date($object->datesp, 'day'); + print '
'.$langs->trans("DateEndPeriod").''; - print dol_print_date($object->dateep, 'day'); - print '
'.$langs->trans("DateEndPeriod").""; + print $form->selectDate($object->dateep, 'dateep', 0, 0, 0, 'dateep', 1); + print "
' . $langs->trans("DateEndPeriod") . ''; + print dol_print_date($object->dateep, 'day'); + print '
'.$langs->trans("DatePayment").''; print dol_print_date($object->datep, 'day'); print '
'.$langs->trans("DateValue").''; print dol_print_date($object->datev, 'day'); + print '
' . $langs->trans("Amount") . '
' . $langs->trans("Amount") . '' . price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency) . '
'; + print ''; + if ($action != 'editmode') + print ''; + print '
'; + print $langs->trans('PaymentMode'); + print 'id.'">'.img_edit($langs->trans('SetMode'), 1).'
'; + print '
'; + + if ($action == 'editmode') { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id'); + } else { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none'); + } print '
'.$langs->trans("Amount").''.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('BankTransactionLine').''; - print $bankline->getNomUrl(1, 0, 'showall'); - print '
'; + print ''; + print '
'; + print $langs->trans('BankAccount'); + print ''; + if ($action != 'editbankaccount' && $user->rights->salaries->write) + print 'id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'
'; + print '
'; + if ($action == 'editbankaccount') { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + } else { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); } + print '
'; + print ''; + print ''; + print ''; + print ''; + if (!empty($conf->banque->enabled)) { + print ''; + } + print ''; + print ''; + + if ($num > 0) + { + $bankaccountstatic = new Account($db); + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + print ''; + print '\n"; + $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type; + print "\n"; + if (!empty($conf->banque->enabled)) + { + $bankaccountstatic->id = $objp->baid; + $bankaccountstatic->ref = $objp->baref; + $bankaccountstatic->label = $objp->baref; + $bankaccountstatic->number = $objp->banumber; + $bankaccountstatic->currency_code = $objp->bacurrency_code; + + if (!empty($conf->accounting->enabled)) { + $bankaccountstatic->account_number = $objp->account_number; + + $accountingjournal = new AccountingJournal($db); + $accountingjournal->fetch($objp->fk_accountancy_journal); + $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1); + } + + print ''; + } + print '\n"; + print ""; + $totalpaye += $objp->amount; + $i++; + } + } + else { + print ''; + print ''; + print ''; + } + + print '\n"; + print '\n"; + + $resteapayer = $object->amount - $totalpaye; + $cssforamountpaymentcomplete = 'amountpaymentcomplete'; + + print '"; + print '\n"; + + print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans('BankAccount').''.$langs->trans("Amount").'
'; + print ''.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp), 'day')."".$labeltype.' '.$objp->num_payment."'; + if ($bankaccountstatic->id) + print $bankaccountstatic->getNomUrl(1, 'transactions'); + print ''.price($objp->amount)."
'.$langs->trans("None").'
'.$langs->trans("AlreadyPaid")." :".price($totalpaye)."
'.$langs->trans("AmountExpected")." :".price($object->amount)."
'.$langs->trans("RemainderToPay")." :'.price($resteapayer)."
"; + print '
'; + + $db->free($resql); + } + else { + dol_print_error($db); + } + + print ''; + print ''; + print ''; + + print '
'; + + dol_fiche_end(); + + if ($action == 'edit') + { + print '
'; + print ''; + print '   '; + print ''; + print '
'; + print "\n"; + } + print dol_get_fiche_end(); // Action buttons print '
'."\n"; - if ($object->rappro == 0) + if ($action != 'edit') { - if (!empty($user->rights->salaries->delete)) + // Reopen + if ($object->paye && $user->rights->salaries->write) { - print ''; - } else { - print ''; + print ""; + } + + // Edit + if ($object->paye == 0 && $user->rights->salaries->write) + { + print ""; + } + + // Emit payment + if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->rights->salaries->write) + { + print ""; + } + + // Classify 'paid' + if ($object->paye == 0 + && ( + (round($resteapayer) <= 0 && $object->amount > 0) + || (round($resteapayer) >= 0 && $object->amount < 0) + ) + && $user->rights->salaries->write) + { + print ""; + } + + // Clone + if ($user->rights->salaries->write) + { + print ""; + } + + if (!empty($user->rights->salaries->delete) && empty($totalpaye)) + { + print ''; + } + else { + print ''; } - } else { - print ''; } print "
"; } diff --git a/htdocs/salaries/class/paymentsalary.class.php b/htdocs/salaries/class/paymentsalary.class.php index 59cf90e72e7..5409dd42fb8 100644 --- a/htdocs/salaries/class/paymentsalary.class.php +++ b/htdocs/salaries/class/paymentsalary.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2014 Juanjo Menent + * 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 @@ -24,10 +25,11 @@ // Put here all includes required by your class file require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; /** - * Class to manage salary payments + * Class to manage payments of social contributions */ class PaymentSalary extends CommonObject { @@ -44,56 +46,57 @@ class PaymentSalary extends CommonObject /** * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png */ - public $picto = 'salary'; - - public $tms; + public $picto = 'payment'; /** - * @var int User ID - */ - public $fk_user; + * @var int ID + */ + public $fk_salary; - public $datep; - public $datev; - public $amount; + public $datec = ''; + public $tms = ''; + public $datep = ''; /** - * @var int ID + * @deprecated + * @see $amount */ - public $fk_project; + public $total; - public $type_payment; + public $amount; // Total amount of payment + public $amounts = array(); // Array of amounts + + /** + * @var int ID + */ + public $fk_typepaiement; + + /** + * @var string + * @deprecated + */ + public $num_paiement; + + /** + * @var string + */ public $num_payment; /** - * @var string salary payments label - */ - public $label; - - public $datesp; - public $dateep; - - /** - * @var int ID - */ + * @var int ID + */ public $fk_bank; /** - * @var int ID - */ - public $fk_user_author; + * @var int ID + */ + public $fk_user_creat; /** - * @var int ID - */ + * @var int ID + */ public $fk_user_modif; - /** - * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. - */ - public $fields = array(); - - /** * Constructor * @@ -102,165 +105,266 @@ class PaymentSalary extends CommonObject public function __construct($db) { $this->db = $db; - $this->element = 'payment_salary'; - $this->table_element = 'payment_salary'; } /** - * Update database - * - * @param User $user User that modify - * @param int $notrigger 0=no, 1=yes (no update trigger) - * @return int <0 if KO, >0 if OK + * Create payment of social contribution into database. + * Use this->amounts to have list of lines for the payment + * + * @param User $user User making payment + * @param int $closepaidcontrib 1=Also close payed contributions to paid, 0=Do nothing more + * @return int <0 if KO, id of payment if OK */ - public function update($user = null, $notrigger = 0) + public function create($user, $closepaidcontrib = 0) { global $conf, $langs; $error = 0; - // Clean parameters - $this->amount = trim($this->amount); - $this->label = trim($this->label); - $this->note = trim($this->note); + $now = dol_now(); - // Check parameters - if (empty($this->fk_user) || $this->fk_user < 0) { - $this->error = 'ErrorBadParameter'; + dol_syslog(get_class($this)."::create", LOG_DEBUG); + + // Validate parametres + if (!$this->datepaye) + { + $this->error = 'ErrorBadValueForParameterCreatePaymentSocialContrib'; return -1; } + // Clean parameters + if (isset($this->fk_salary)) $this->fk_salary = (int) $this->fk_salary; + if (isset($this->amount)) $this->amount = trim($this->amount); + if (isset($this->fk_typepaiement)) $this->fk_typepaiement = (int) $this->fk_typepaiement; + if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement); // deprecated + if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); + if (isset($this->note)) $this->note = trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; + if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; + if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; + + $totalamount = 0; + foreach ($this->amounts as $key => $value) // How payment is dispatch + { + $newvalue = price2num($value, 'MT'); + $this->amounts[$key] = $newvalue; + $totalamount += $newvalue; + } + $totalamount = price2num($totalamount); + + // Check parameters + if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null + + $this->db->begin(); - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET"; + if ($totalamount != 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (fk_salary, datec, datep, amount,"; + $sql .= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)"; + $sql .= " VALUES ($this->chid, '".$this->db->idate($now)."',"; + $sql .= " '".$this->db->idate($this->datepaye)."',"; + $sql .= " ".$totalamount.","; + $sql .= " ".$this->paiementtype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.","; + $sql .= " 0)"; - $sql .= " tms='".$this->db->idate($this->tms)."',"; - $sql .= " fk_user=".$this->fk_user.","; - $sql .= " datep='".$this->db->idate($this->datep)."',"; - $sql .= " datev='".$this->db->idate($this->datev)."',"; - $sql .= " amount=".price2num($this->amount).","; - $sql .= " fk_projet=".((int) $this->fk_project).","; - $sql .= " fk_typepayment=".$this->fk_typepayment."',"; - $sql .= " num_payment='".$this->db->escape($this->num_payment)."',"; - $sql .= " label='".$this->db->escape($this->label)."',"; - $sql .= " datesp='".$this->db->idate($this->datesp)."',"; - $sql .= " dateep='".$this->db->idate($this->dateep)."',"; - $sql .= " note='".$this->db->escape($this->note)."',"; - $sql .= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").","; - $sql .= " fk_user_author=".((int) $this->fk_user_author).","; - $sql .= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : 'null'); + $resql = $this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary"); - $sql .= " WHERE rowid=".$this->id; + // Insere tableau des montants / factures + foreach ($this->amounts as $key => $amount) + { + $contribid = $key; + if (is_numeric($amount) && $amount <> 0) + { + $amount = price2num($amount); - dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $this->error = "Error ".$this->db->lasterror(); + // If we want to closed payed invoices + if ($closepaidcontrib) + { + $contrib = new Salary($this->db); + $contrib->fetch($contribid); + $paiement = $contrib->getSommePaiement(); + //$creditnotes=$contrib->getSumCreditNotesUsed(); + $creditnotes = 0; + //$deposits=$contrib->getSumDepositsUsed(); + $deposits = 0; + $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT'); + $remaintopay = price2num($contrib->amount - $paiement - $creditnotes - $deposits, 'MT'); + if ($remaintopay == 0) + { + $result = $contrib->set_paid($user); + } + else dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing."); + } + } + } + } + else + { + $error++; + } + } + + $result = $this->call_trigger('PAYMENTSOCIALCONTRIBUTION_CREATE', $user); + if ($result < 0) $error++; + + if ($totalamount != 0 && !$error) + { + $this->amount = $totalamount; + $this->total = $totalamount; // deprecated + $this->db->commit(); + return $this->id; + } + else + { + $this->error = $this->db->error(); + $this->db->rollback(); return -1; } + } - // Update extrafield - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; + /** + * Load object in memory from database + * + * @param int $id Id object + * @return int <0 if KO, >0 if OK + */ + public function fetch($id) + { + global $langs; + $sql = "SELECT"; + $sql .= " t.rowid,"; + $sql .= " t.fk_salary,"; + $sql .= " t.datec,"; + $sql .= " t.tms,"; + $sql .= " t.datep,"; + $sql .= " t.amount,"; + $sql .= " t.fk_typepaiement,"; + $sql .= " t.num_paiement as num_payment,"; + $sql .= " t.note,"; + $sql .= " t.fk_bank,"; + $sql .= " t.fk_user_creat,"; + $sql .= " t.fk_user_modif,"; + $sql .= " pt.code as type_code, pt.libelle as type_label,"; + $sql .= ' b.fk_account'; + $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepaiement = pt.id"; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; + $sql .= " WHERE t.rowid = ".$id; + // TODO link on entity of tax; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + + $this->fk_salary = $obj->fk_salary; + $this->datec = $this->db->jdate($obj->datec); + $this->tms = $this->db->jdate($obj->tms); + $this->datep = $this->db->jdate($obj->datep); + $this->amount = $obj->amount; + $this->fk_typepaiement = $obj->fk_typepaiement; + $this->num_paiement = $obj->num_payment; + $this->num_payment = $obj->num_payment; + $this->note = $obj->note; + $this->fk_bank = $obj->fk_bank; + $this->fk_user_creat = $obj->fk_user_creat; + $this->fk_user_modif = $obj->fk_user_modif; + + $this->type_code = $obj->type_code; + $this->type_label = $obj->type_label; + + $this->bank_account = $obj->fk_account; + $this->bank_line = $obj->fk_bank; } - } + $this->db->free($resql); - if (!$notrigger) { - // Call trigger - $result = $this->call_trigger('PAYMENT_SALARY_MODIFY', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - - if (!$error) { - $this->db->commit(); return 1; - } else { - $this->db->rollback(); + } + else + { + $this->error = "Error ".$this->db->lasterror(); return -1; } } /** - * Load object in memory from database + * Update database * - * @param int $id id object - * @param User $user User that load - * @return int <0 if KO, >0 if OK + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK */ - public function fetch($id, $user = null) + public function update($user = null, $notrigger = 0) { - global $langs; + global $conf, $langs; + $error = 0; - $sql = "SELECT"; - $sql .= " s.rowid,"; + // Clean parameters - $sql .= " s.tms,"; - $sql .= " s.fk_user,"; - $sql .= " s.datep,"; - $sql .= " s.datev,"; - $sql .= " s.amount,"; - $sql .= " s.fk_projet as fk_project,"; - $sql .= " s.fk_typepayment,"; - $sql .= " s.num_payment,"; - $sql .= " s.label,"; - $sql .= " s.datesp,"; - $sql .= " s.dateep,"; - $sql .= " s.note,"; - $sql .= " s.fk_bank,"; - $sql .= " s.fk_user_author,"; - $sql .= " s.fk_user_modif,"; - $sql .= " b.fk_account,"; - $sql .= " b.fk_type,"; - $sql .= " b.rappro"; + if (isset($this->fk_salary)) $this->fk_salary = (int) $this->fk_salary; + if (isset($this->amount)) $this->amount = trim($this->amount); + if (isset($this->fk_typepaiement)) $this->fk_typepaiement = (int) $this->fk_typepaiement; + if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement); // deprecated + if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); + if (isset($this->note)) $this->note = trim($this->note); + if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; + if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; + if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; - $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as s"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid"; - $sql .= " WHERE s.rowid = ".$id; - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + + // Check parameters + // Put here code to add control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET"; + + $sql .= " fk_salary=".(isset($this->fk_salary) ? $this->fk_salary : "null").","; + $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; + $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; + $sql .= " datep=".(dol_strlen($this->datep) != 0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; + $sql .= " amount=".(isset($this->amount) ? $this->amount : "null").","; + $sql .= " fk_typepaiement=".(isset($this->fk_typepaiement) ? $this->fk_typepaiement : "null").","; + $sql .= " num_paiement=".(isset($this->num_paiement) ? "'".$this->db->escape($this->num_paiement)."'" : "null").","; + $sql .= " note=".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : "null").","; + $sql .= " fk_bank=".(isset($this->fk_bank) ? $this->fk_bank : "null").","; + $sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").","; + $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null").""; + + + $sql .= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::update", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - $this->tms = $this->db->jdate($obj->tms); - $this->fk_user = $obj->fk_user; - $this->datep = $this->db->jdate($obj->datep); - $this->datev = $this->db->jdate($obj->datev); - $this->amount = $obj->amount; - $this->fk_project = $obj->fk_project; - $this->type_payement = $obj->fk_typepayment; - $this->num_payment = $obj->num_payment; - $this->label = $obj->label; - $this->datesp = $this->db->jdate($obj->datesp); - $this->dateep = $this->db->jdate($obj->dateep); - $this->note = $obj->note; - $this->fk_bank = $obj->fk_bank; - $this->fk_user_author = $obj->fk_user_author; - $this->fk_user_modif = $obj->fk_user_modif; - $this->fk_account = $obj->fk_account; - $this->fk_type = $obj->fk_type; - $this->rappro = $obj->rappro; - - // Retrieve all extrafield - // fetch optionals attributes and labels - $this->fetch_optionals(); + // Commit or rollback + if ($error) + { + foreach ($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } - $this->db->free($resql); - + $this->db->rollback(); + return -1 * $error; + } + else + { + $this->db->commit(); return 1; - } else { - $this->error = "Error ".$this->db->lasterror(); - return -1; } } @@ -268,407 +372,258 @@ class PaymentSalary extends CommonObject /** * Delete object in database * - * @param User $user User that delete - * @return int <0 if KO, >0 if OK + * @param User $user User that delete + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK */ - public function delete($user) + public function delete($user, $notrigger = 0) { global $conf, $langs; - $error = 0; - // Call trigger - $result = $this->call_trigger('PAYMENT_SALARY_DELETE', $user); - if ($result < 0) { - return -1; - } - // End call triggers - - // Delete donation - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary_extrafields"; - $sql .= " WHERE fk_object=".$this->id; - - $resql = $this->db->query($sql); - if (!$resql) { - $this->errors[] = $this->db->lasterror(); - $error++; - } - } - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary"; - $sql .= " WHERE rowid=".$this->id; - - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $this->error = "Error ".$this->db->lasterror(); - return -1; - } - - return 1; - } - - - /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void - */ - public function initAsSpecimen() - { - $this->id = 0; - - $this->tms = ''; - $this->fk_user = 1; - $this->datep = ''; - $this->datev = ''; - $this->amount = ''; - $this->label = ''; - $this->datesp = ''; - $this->dateep = ''; - $this->note = ''; - $this->fk_bank = ''; - $this->fk_user_author = 1; - $this->fk_user_modif = 1; - } - - /** - * Create in database - * - * @param User $user User that create - * @return int <0 if KO, >0 if OK - */ - public function create($user) - { - global $conf, $langs; - - $error = 0; - $now = dol_now(); - - // Clean parameters - $this->amount = price2num(trim($this->amount)); - $this->label = trim($this->label); - $this->note = trim($this->note); - $this->fk_bank = (int) $this->fk_bank; - $this->fk_user_author = (int) $this->fk_user_author; - $this->fk_user_modif = (int) $this->fk_user_modif; - - // Check parameters - if (!$this->label) { - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")); - return -3; - } - if ($this->fk_user <= 0 || $this->fk_user == '') { - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee")); - return -4; - } - if ($this->amount < 0 || $this->amount == '') { - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")); - return -5; - } - if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0)) { - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account")); - return -6; - } - if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0)) { - $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")); - return -7; - } + dol_syslog(get_class($this)."::delete"); $this->db->begin(); - // Insert into llx_payment_salary - $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_salary (fk_user"; - $sql .= ", datep"; - $sql .= ", datev"; - $sql .= ", amount"; - $sql .= ", fk_projet"; - $sql .= ", salary"; - $sql .= ", fk_typepayment"; - $sql .= ", num_payment"; - if ($this->note) { - $sql .= ", note"; - } - $sql .= ", label"; - $sql .= ", datesp"; - $sql .= ", dateep"; - $sql .= ", fk_user_author"; - $sql .= ", datec"; - $sql .= ", fk_bank"; - $sql .= ", entity"; - $sql .= ") "; - $sql .= " VALUES ("; - $sql .= "'".$this->db->escape($this->fk_user)."'"; - $sql .= ", '".$this->db->idate($this->datep)."'"; - $sql .= ", '".$this->db->idate($this->datev)."'"; - $sql .= ", ".$this->amount; - $sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 0); - $sql .= ", ".($this->salary > 0 ? $this->salary : "null"); - $sql .= ", ".$this->db->escape($this->type_payment); - $sql .= ", '".$this->db->escape($this->num_payment)."'"; - if ($this->note) { - $sql .= ", '".$this->db->escape($this->note)."'"; - } - $sql .= ", '".$this->db->escape($this->label)."'"; - $sql .= ", '".$this->db->idate($this->datesp)."'"; - $sql .= ", '".$this->db->idate($this->dateep)."'"; - $sql .= ", '".$this->db->escape($user->id)."'"; - $sql .= ", '".$this->db->idate($now)."'"; - $sql .= ", NULL"; - $sql .= ", ".$conf->entity; - $sql .= ")"; - - dol_syslog(get_class($this)."::create", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_salary"); - - if ($this->id > 0) { - if (!empty($conf->banque->enabled) && !empty($this->amount)) { - // Insert into llx_bank - require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; - - $acc = new Account($this->db); - $result = $acc->fetch($this->accountid); - if ($result <= 0) { - dol_print_error($this->db); - } - - // Update extrafield - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } - } - - // Insert payment into llx_bank - // Add link 'payment_salary' in bank_url between payment and bank transaction - $bank_line_id = $acc->addline( - $this->datep, - $this->type_payment, - $this->label, - -abs($this->amount), - $this->num_payment, - '', - $user, - '', - '', - '', - $this->datev - ); - - // Update fk_bank into llx_paiement. - // So we know the payment which has generate the banking ecriture - if ($bank_line_id > 0) { - $this->update_fk_bank($bank_line_id); - } else { - $this->error = $acc->error; - $error++; - } - - if (!$error) { - // Add link 'payment_salary' in bank_url between payment and bank transaction - $url = DOL_URL_ROOT.'/salaries/card.php?id='; - - $result = $acc->add_url_line($bank_line_id, $this->id, $url, "(SalaryPayment)", "payment_salary"); - if ($result <= 0) { - $this->error = $acc->error; - $error++; - } - } - - $fuser = new User($this->db); - $fuser->fetch($this->fk_user); - - // Add link 'user' in bank_url between operation and bank transaction - $result = $acc->add_url_line( - $bank_line_id, - $this->fk_user, - DOL_URL_ROOT.'/user/card.php?id=', - $fuser->getFullName($langs), - // $langs->trans("SalaryPayment").' '.$fuser->getFullName($langs).' '.dol_print_date($this->datesp,'dayrfc').' '.dol_print_date($this->dateep,'dayrfc'), - 'user' - ); - - if ($result <= 0) { - $this->error = $acc->error; - $error++; - } - } - - // Call trigger - $result = $this->call_trigger('PAYMENT_SALARY_CREATE', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } else { + if ($this->bank_line > 0) + { + $accline = new AccountLine($this->db); + $accline->fetch($this->bank_line); + $result = $accline->delete(); + if ($result < 0) { + $this->errors[] = $accline->error; $error++; } + } - if (!$error) { - $this->db->commit(); - return $this->id; - } else { - $this->db->rollback(); - return -2; + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_salary"; + $sql .= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + } + + // Commit or rollback + if ($error) + { + foreach ($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } - } else { - $this->error = $this->db->error(); + $this->db->rollback(); + return -1 * $error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + + /** + * Load an object from its id and create a new one in database + * + * @param User $user User making the clone + * @param int $fromid Id of object to clone + * @return int New id of clone + */ + public function createFromClone(User $user, $fromid) + { + $error = 0; + + $object = new PaymentSocialContribution($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + $object->id = 0; + $object->statut = 0; + + // Clear fields + // ... + + // Create clone + $object->context['createfromclone'] = 'createfromclone'; + $result = $object->create($user); + + // Other options + if ($result < 0) + { + $this->error = $object->error; + $error++; + } + + unset($object->context['createfromclone']); + + // End + if (!$error) + { + $this->db->commit(); + return $object->id; + } + else + { $this->db->rollback(); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** - * Update link between payment salary and line generate into llx_bank + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + public function initAsSpecimen() + { + $this->id = 0; + + $this->fk_salary = ''; + $this->datec = ''; + $this->tms = ''; + $this->datep = ''; + $this->amount = ''; + $this->fk_typepaiement = ''; + $this->num_payment = ''; + $this->note_private = ''; + $this->note_public = ''; + $this->fk_bank = ''; + $this->fk_user_creat = ''; + $this->fk_user_modif = ''; + } + + + /** + * Add record into bank for payment with links between this bank record and invoices of payment. + * All payment properties must have been set first like after a call to create(). + * + * @param User $user Object of user making payment + * @param string $mode 'payment_sc' + * @param string $label Label to use in bank record + * @param int $accountid Id of bank account to do link with + * @param string $emetteur_nom Name of transmitter + * @param string $emetteur_banque Name of bank + * @return int <0 if KO, >0 if OK + */ + public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque) + { + global $conf; + + // Clean data + $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement); + + $error = 0; + + if (!empty($conf->banque->enabled)) + { + include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + + $acc = new Account($this->db); + $acc->fetch($accountid); + + $total = $this->amount; + + // Insert payment into llx_bank + $bank_line_id = $acc->addline( + $this->datepaye, + $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example") + $label, + -$total, + $this->num_payment, + '', + $user, + $emetteur_nom, + $emetteur_banque, + '', + $this->datev + ); + + // Mise a jour fk_bank dans llx_paiement. + // On connait ainsi le paiement qui a genere l'ecriture bancaire + if ($bank_line_id > 0) + { + $result = $this->update_fk_bank($bank_line_id); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + + // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction + $url = ''; + if ($mode == 'payment_salary') $url = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='; + if ($url) + { + $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + } + + // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) + $linkaddedforthirdparty = array(); + foreach ($this->amounts as $key => $value) + { + if ($mode == 'payment_salary') + { + $socialcontrib = new Salary($this->db); + $socialcontrib->fetch($key); + $result = $acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_label.(($socialcontrib->lib && $socialcontrib->lib != $socialcontrib->type_label) ? ' ('.$socialcontrib->lib.')' : ''), 'salary'); + if ($result <= 0) dol_print_error($this->db); + } + } + } + else + { + $this->error = $acc->error; + $error++; + } + } + + if (!$error) + { + return 1; + } + else + { + return -1; + } + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Mise a jour du lien entre le paiement de salaire et la ligne dans llx_bank generee * - * @param int $id_bank Id bank account - * @return int <0 if KO, >0 if OK + * @param int $id_bank Id if bank + * @return int >0 if OK, <=0 if KO */ public function update_fk_bank($id_bank) { - // phpcs:enable - $sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_salary SET fk_bank = '.$id_bank; - $sql .= ' WHERE rowid = '.$this->id; + // phpcs:enable + $sql = "UPDATE ".MAIN_DB_PREFIX."payment_salary SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) { + if ($result) + { return 1; - } else { - dol_print_error($this->db); - return -1; } - } - - - /** - * Send name clicable (with possibly the picto) - * - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @param string $option link option - * @param int $notooltip 1=Disable tooltip - * @param string $morecss Add more css on link - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking - * @return string Chaine with URL - */ - public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) - { - global $db, $conf, $langs, $hookmanager; - - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } - - $result = ''; - - $label = img_picto('', $this->picto).' '.$langs->trans("SalaryPayment").''; - $label .= '
'.$langs->trans('Ref').': '.$this->ref; - if (!empty($this->label)) { - $labeltoshow = $this->label; - $reg = array(); - if (preg_match('/^\((.*)\)$/i', $this->label, $reg)) { - // Label generique car entre parentheses. On l'affiche en le traduisant - if ($reg[1] == 'paiement') { - $reg[1] = 'Payment'; - } - $labeltoshow = $langs->trans($reg[1]); - } - $label .= '
'.$langs->trans('Label').': '.$labeltoshow; - } - - $url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id; - - if ($option != 'nolink') { - // Add param to save lastsearch_values or not - $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } - } - - $linkclose = ''; - if (empty($notooltip)) { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { - $label = $langs->trans("ShowMyObject"); - $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; - - /* - $hookmanager->initHooks(array('myobjectdao')); - $parameters=array('id'=>$this->id); - $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) $linkclose = $hookmanager->resPrint; - */ - } else { - $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); - } - - $linkstart = ''; - $linkend = ''; - - $result .= $linkstart; - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= $this->ref; - } - $result .= $linkend; - //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); - - global $action, $hookmanager; - $hookmanager->initHooks(array('salarypayment')); - $parameters = array('id'=>$this->id, 'getnomurl'=>$result); - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } - - return $result; - } - - /** - * Information on record - * - * @param int $id Id of record - * @return void - */ - public function info($id) - { - $sql = 'SELECT ps.rowid, ps.datec, ps.fk_user_author'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps'; - $sql .= ' WHERE ps.rowid = '.$id; - - dol_syslog(get_class($this).'::info', LOG_DEBUG); - $result = $this->db->query($sql); - - if ($result) { - if ($this->db->num_rows($result)) { - $obj = $this->db->fetch_object($result); - $this->id = $obj->rowid; - if ($obj->fk_user_author) { - $cuser = new User($this->db); - $cuser->fetch($obj->fk_user_author); - $this->user_creation = $cuser; - } - $this->date_creation = $this->db->jdate($obj->datec); - } - $this->db->free($result); - } else { - dol_print_error($this->db); + else + { + $this->error = $this->db->error(); + return 0; } } @@ -684,7 +639,7 @@ class PaymentSalary extends CommonObject return $this->LibStatut($this->statut, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Renvoi le libelle d'un statut donne * @@ -694,45 +649,73 @@ class PaymentSalary extends CommonObject */ public function LibStatut($status, $mode = 0) { - // phpcs:enable + // phpcs:enable global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage $langs->load('compta'); /*if ($mode == 0) - { + { if ($status == 0) return $langs->trans('ToValidate'); if ($status == 1) return $langs->trans('Validated'); - } - if ($mode == 1) - { + } + if ($mode == 1) + { if ($status == 0) return $langs->trans('ToValidate'); if ($status == 1) return $langs->trans('Validated'); - } - if ($mode == 2) - { + } + if ($mode == 2) + { if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate'); if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated'); - } - if ($mode == 3) - { + } + if ($mode == 3) + { if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1'); if ($status == 1) return img_picto($langs->trans('Validated'),'statut4'); - } - if ($mode == 4) - { + } + if ($mode == 4) + { if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate'); if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated'); - } - if ($mode == 5) - { + } + if ($mode == 5) + { if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1'); if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4'); - } - if ($mode == 6) - { + } + if ($mode == 6) + { if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1'); if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4'); - }*/ + }*/ return ''; } + + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $maxlen Longueur max libelle + * @return string Chaine avec URL + */ + public function getNomUrl($withpicto = 0, $maxlen = 0) + { + global $langs; + + $result = ''; + + if (empty($this->ref)) $this->ref = $this->lib; + $label = $langs->trans("ShowPayment").': '.$this->ref; + + if (!empty($this->id)) { + $link = ''; + $linkend = ''; + + if ($withpicto) $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); + if ($withpicto && $withpicto != 2) $result .= ' '; + if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend; + } + + return $result; + } } diff --git a/htdocs/salaries/class/salariesstats.class.php b/htdocs/salaries/class/salariesstats.class.php index 0fcef8682a8..195cd1b342e 100644 --- a/htdocs/salaries/class/salariesstats.class.php +++ b/htdocs/salaries/class/salariesstats.class.php @@ -1,6 +1,7 @@ * Copyright (c) 2018 Fidesio + * 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 @@ -80,7 +81,7 @@ class SalariesStats extends Stats $sql = "SELECT YEAR(datep) as dm, count(*)"; $sql .= " FROM ".$this->from; $sql .= " GROUP BY dm DESC"; - $sql .= " WHERE ".$this->where; + //$sql .= " WHERE ".$this->where; return $this->_getNbByYear($sql); } @@ -98,7 +99,7 @@ class SalariesStats extends Stats $sql = "SELECT MONTH(datep) as dm, count(*)"; $sql .= " FROM ".$this->from; $sql .= " WHERE YEAR(datep) = ".$year; - $sql .= " AND ".$this->where; + //$sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); @@ -120,7 +121,7 @@ class SalariesStats extends Stats $sql = "SELECT date_format(datep,'%m') as dm, sum(".$this->field.")"; $sql .= " FROM ".$this->from; $sql .= " WHERE date_format(datep,'%Y') = '".$this->db->escape($year)."'"; - $sql .= " AND ".$this->where; + //$sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); @@ -141,7 +142,7 @@ class SalariesStats extends Stats $sql = "SELECT date_format(datep,'%m') as dm, avg(".$this->field.")"; $sql .= " FROM ".$this->from; $sql .= " WHERE date_format(datep,'%Y') = '".$this->db->escape($year)."'"; - $sql .= " AND ".$this->where; + //$sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); @@ -157,7 +158,7 @@ class SalariesStats extends Stats { $sql = "SELECT date_format(datep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; $sql .= " FROM ".$this->from; - $sql .= " WHERE ".$this->where; + //$sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; $sql .= $this->db->order('year', 'DESC'); diff --git a/htdocs/salaries/class/salary.class.php b/htdocs/salaries/class/salary.class.php new file mode 100644 index 00000000000..42a59c7ed05 --- /dev/null +++ b/htdocs/salaries/class/salary.class.php @@ -0,0 +1,755 @@ + + * Copyright (C) 2014 Juanjo Menent + * 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/class/salary.class.php + * \ingroup salaries + * \brief Class for salaries module payment + */ + +// Put here all includes required by your class file +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; + + +/** + * Class to manage salary payments + */ +class Salary extends CommonObject +{ + /** + * @var string ID to identify managed object + */ + public $element = 'salary'; + + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'salary'; + + /** + * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png + */ + public $picto = 'payment'; + + public $tms; + + /** + * @var int User ID + */ + public $fk_user; + + public $datep; + public $datev; + public $amount; + + /** + * @var int ID + */ + public $fk_project; + + public $type_payment; + public $num_payment; + + /** + * @var string salary payments label + */ + public $label; + + public $datesp; + public $dateep; + + /** + * @var int ID + */ + public $fk_bank; + + /** + * @var int ID + */ + public $fk_user_author; + + /** + * @var int ID + */ + public $fk_user_modif; + + const STATUS_UNPAID = 0; + const STATUS_PAID = 1; + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + $this->element = 'salary'; + $this->table_element = 'salary'; + } + + /** + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=no, 1=yes (no update trigger) + * @return int <0 if KO, >0 if OK + */ + public function update($user = null, $notrigger = 0) + { + global $conf, $langs; + + $error = 0; + + // Clean parameters + $this->amount = trim($this->amount); + $this->label = trim($this->label); + $this->note = trim($this->note); + + // Check parameters + if (empty($this->fk_user) || $this->fk_user < 0) + { + $this->error = 'ErrorBadParameter'; + return -1; + } + + $this->db->begin(); + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET"; + + $sql .= " tms='".$this->db->idate(dol_now())."',"; + $sql .= " fk_user=".$this->fk_user.","; + /*$sql .= " datep='".$this->db->idate($this->datep)."',"; + $sql .= " datev='".$this->db->idate($this->datev)."',";*/ + $sql .= " amount=".price2num($this->amount).","; + $sql .= " fk_projet=".((int) $this->fk_project).","; + $sql .= " fk_typepayment=".$this->type_payment.","; + $sql .= " num_payment='".$this->db->escape($this->num_payment)."',"; + $sql .= " label='".$this->db->escape($this->label)."',"; + $sql .= " datesp='".$this->db->idate($this->datesp)."',"; + $sql .= " dateep='".$this->db->idate($this->dateep)."',"; + $sql .= " note='".$this->db->escape($this->note)."',"; + $sql .= " fk_bank=".($this->fk_bank > 0 ? (int) $this->fk_bank : "null").","; + $sql .= " fk_user_author=".((int) $this->fk_user_author).","; + $sql .= " fk_user_modif=".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : 'null'); + + $sql .= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) + { + $this->error = "Error ".$this->db->lasterror(); + return -1; + } + + // Update extrafield + if (!$error) + { + if (!$error) + { + $result = $this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + + if (!$notrigger) + { + // Call trigger + $result = $this->call_trigger('salary_MODIFY', $user); + if ($result < 0) $error++; + // End call triggers + } + + if (!$error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * Load object in memory from database + * + * @param int $id id object + * @param User $user User that load + * @return int <0 if KO, >0 if OK + */ + public function fetch($id, $user = null) + { + global $langs; + $sql = "SELECT"; + $sql .= " s.rowid,"; + + $sql .= " s.tms,"; + $sql .= " s.fk_user,"; + $sql .= " s.datep,"; + $sql .= " s.datev,"; + $sql .= " s.amount,"; + $sql .= " s.fk_projet as fk_project,"; + $sql .= " s.fk_typepayment,"; + $sql .= " s.num_payment,"; + $sql .= " s.label,"; + $sql .= " s.datesp,"; + $sql .= " s.dateep,"; + $sql .= " s.note,"; + $sql .= " s.paye,"; + $sql .= " s.fk_bank,"; + $sql .= " s.fk_user_author,"; + $sql .= " s.fk_user_modif,"; + $sql .= " s.fk_account"; + /*$sql .= " b.fk_type,"; + $sql .= " b.rappro";*/ + + $sql .= " FROM ".MAIN_DB_PREFIX."salary as s"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid"; + $sql .= " WHERE s.rowid = ".$id; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->tms = $this->db->jdate($obj->tms); + $this->fk_user = $obj->fk_user; + $this->datep = $this->db->jdate($obj->datep); + $this->datev = $this->db->jdate($obj->datev); + $this->amount = $obj->amount; + $this->fk_project = $obj->fk_project; + $this->type_payment = $obj->fk_typepayment; + $this->num_payment = $obj->num_payment; + $this->label = $obj->label; + $this->datesp = $this->db->jdate($obj->datesp); + $this->dateep = $this->db->jdate($obj->dateep); + $this->note = $obj->note; + $this->paye = $obj->paye; + $this->fk_bank = $obj->fk_bank; + $this->fk_user_author = $obj->fk_user_author; + $this->fk_user_modif = $obj->fk_user_modif; + $this->fk_account = $this->accountid = $obj->fk_account; + $this->fk_type = $obj->fk_type; + $this->rappro = $obj->rappro; + + // Retreive all extrafield + // fetch optionals attributes and labels + $this->fetch_optionals(); + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error = "Error ".$this->db->lasterror(); + return -1; + } + } + + + /** + * Delete object in database + * + * @param User $user User that delete + * @return int <0 if KO, >0 if OK + */ + public function delete($user) + { + global $conf, $langs; + + $error = 0; + + // Call trigger + $result = $this->call_trigger('salary_DELETE', $user); + if ($result < 0) return -1; + // End call triggers + + // Delete donation + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."salary_extrafields"; + $sql .= " WHERE fk_object=".$this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $this->errors[] = $this->db->lasterror(); + $error++; + } + } + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."salary"; + $sql .= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) + { + $this->error = "Error ".$this->db->lasterror(); + return -1; + } + + return 1; + } + + + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + public function initAsSpecimen() + { + $this->id = 0; + + $this->tms = ''; + $this->fk_user = ''; + $this->datep = ''; + $this->datev = ''; + $this->amount = ''; + $this->label = ''; + $this->datesp = ''; + $this->dateep = ''; + $this->note = ''; + $this->fk_bank = ''; + $this->fk_user_author = ''; + $this->fk_user_modif = ''; + } + + /** + * Create in database + * + * @param User $user User that create + * @return int <0 if KO, >0 if OK + */ + public function create($user) + { + global $conf, $langs; + + $error = 0; + $now = dol_now(); + + // Clean parameters + $this->amount = price2num(trim($this->amount)); + $this->label = trim($this->label); + $this->note = trim($this->note); + $this->fk_bank = trim($this->fk_bank); + $this->fk_user_author = trim($this->fk_user_author); + $this->fk_user_modif = trim($this->fk_user_modif); + $this->accountid = trim($this->accountid); + $this->paye = trim($this->paye); + + // Check parameters + if (!$this->label) + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")); + return -3; + } + if ($this->fk_user < 0 || $this->fk_user == '') + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee")); + return -4; + } + if ($this->amount < 0 || $this->amount == '') + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")); + return -5; + } + /* if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0)) + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account")); + return -6; + } + if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0)) + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")); + return -7; + }*/ + + $this->db->begin(); + + // Insert into llx_salary + $sql = "INSERT INTO ".MAIN_DB_PREFIX."salary (fk_user"; + //$sql .= ", datep"; + //$sql .= ", datev"; + $sql .= ", amount"; + $sql .= ", fk_projet"; + $sql .= ", salary"; + $sql .= ", fk_typepayment"; + $sql .= ", fk_account"; + $sql .= ", num_payment"; + if ($this->note) $sql .= ", note"; + $sql .= ", label"; + $sql .= ", datesp"; + $sql .= ", dateep"; + $sql .= ", fk_user_author"; + $sql .= ", datec"; + $sql .= ", fk_bank"; + $sql .= ", entity"; + $sql .= ") "; + $sql .= " VALUES ("; + $sql .= "'".$this->db->escape($this->fk_user)."'"; + //$sql .= ", '".$this->db->idate($this->datep)."'"; + //$sql .= ", '".$this->db->idate($this->datev)."'"; + $sql .= ", ".$this->amount; + $sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 0); + $sql .= ", ".($this->salary > 0 ? $this->salary : "null"); + $sql .= ", ".($this->type_payment > 0 ? $this->type_payment : 0); + $sql .= ", ".($this->accountid > 0 ? $this->accountid : "null"); + $sql .= ", '".$this->db->escape($this->num_payment)."'"; + if ($this->note) $sql .= ", '".$this->db->escape($this->note)."'"; + $sql .= ", '".$this->db->escape($this->label)."'"; + $sql .= ", '".$this->db->idate($this->datesp)."'"; + $sql .= ", '".$this->db->idate($this->dateep)."'"; + $sql .= ", '".$this->db->escape($user->id)."'"; + $sql .= ", '".$this->db->idate($now)."'"; + $sql .= ", NULL"; + $sql .= ", ".$conf->entity; + $sql .= ")"; + + dol_syslog(get_class($this)."::create", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."salary"); + + if ($this->id > 0) + { + if (!empty($conf->banque->enabled) && !empty($this->amount)) + { + // Insert into llx_bank + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + + $acc = new Account($this->db); + $result = $acc->fetch($this->accountid); + if ($result <= 0) dol_print_error($this->db); + + // Update extrafield + if (!$error) { + if (!$error) + { + $result = $this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + + } + + // Call trigger + $result = $this->call_trigger('salary_CREATE', $user); + if ($result < 0) $error++; + // End call triggers + } + else $error++; + + if (!$error) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -2; + } + } + else + { + $this->error = $this->db->error(); + $this->db->rollback(); + return -1; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Update link between payment salary and line generate into llx_bank + * + * @param int $id_bank Id bank account + * @return int <0 if KO, >0 if OK + */ + public function update_fk_bank($id_bank) + { + // phpcs:enable + $sql = 'UPDATE '.MAIN_DB_PREFIX.'salary SET fk_bank = '.$id_bank; + $sql .= ' WHERE rowid = '.$this->id; + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } + + + /** + * Send name clicable (with possibly the picto) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param string $option link option + * @param int $notooltip 1=Disable tooltip + * @param string $morecss Add more css on link + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @return string Chaine with URL + */ + public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) + { + global $db, $conf, $langs, $hookmanager; + global $dolibarr_main_authentication, $dolibarr_main_demo; + global $menumanager; + + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + + $result = ''; + + $label = ''.$langs->trans("ShowSalaryPayment").''; + $label .= '
'; + $label .= ''.$langs->trans('Ref').': '.$this->ref; + + $url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id; + + if ($option != 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + } + + $linkclose = ''; + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label = $langs->trans("ShowMyObject"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; + + /* + $hookmanager->initHooks(array('myobjectdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook > 0) $linkclose = $hookmanager->resPrint; + */ + } + else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + + $linkstart = ''; + $linkend = ''; + + $result .= $linkstart; + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= $this->ref; + $result .= $linkend; + //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : ''); + + global $action, $hookmanager; + $hookmanager->initHooks(array('salarypayment')); + $parameters = array('id'=>$this->id, 'getnomurl'=>$result); + $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + if ($reshook > 0) $result = $hookmanager->resPrint; + else $result .= $hookmanager->resPrint; + + return $result; + } + + /** + * Return amount of payments already done + * + * @return int Amount of payment already done, <0 if KO + */ + public function getSommePaiement() + { + $table = 'payment_salary'; + $field = 'fk_salary'; + + $sql = 'SELECT sum(amount) as amount'; + $sql .= ' FROM '.MAIN_DB_PREFIX.$table; + $sql .= ' WHERE '.$field.' = '.$this->id; + + dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG); + $resql = $this->db->query($sql); + + if ($resql) { + $amount = 0; + + $obj = $this->db->fetch_object($resql); + if ($obj) $amount = $obj->amount ? $obj->amount : 0; + + $this->db->free($resql); + return $amount; + } + else + { + return -1; + } + } + + /** + * Information on record + * + * @param int $id Id of record + * @return void + */ + public function info($id) + { + $sql = 'SELECT ps.rowid, ps.datec, ps.fk_user_author'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'salary as ps'; + $sql .= ' WHERE ps.rowid = '.$id; + + dol_syslog(get_class($this).'::info', LOG_DEBUG); + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $this->id = $obj->rowid; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + $this->date_creation = $this->db->jdate($obj->datec); + } + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Tag social contribution as payed completely + * + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK + */ + public function set_paid($user) + { + // phpcs:enable + $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET"; + $sql .= " paye = 1"; + $sql .= " WHERE rowid = ".$this->id; + $return = $this->db->query($sql); + if ($return) return 1; + else return -1; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Remove tag payed on social contribution + * + * @param User $user Object user making change + * @return int <0 if KO, >0 if OK + */ + public function set_unpaid($user) + { + // phpcs:enable + $sql = "UPDATE ".MAIN_DB_PREFIX."salary SET"; + $sql .= " paye = 0"; + $sql .= " WHERE rowid = ".$this->id; + $return = $this->db->query($sql); + if ($return) return 1; + else return -1; + } + + + /** + * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle + */ + public function getLibStatut($mode = 0, $alreadypaid = -1) + { + return $this->LibStatut($this->paye, $mode, $alreadypaid); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Renvoi le libelle d'un statut donne + * + * @param int $status Id status + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto + * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) + * @return string Label + */ + public function LibStatut($status, $mode = 0, $alreadypaid = -1) + { + // phpcs:enable + global $langs; + + // Load translation files required by the page + $langs->loadLangs(array("customers", "bills")); + + // We reinit status array to force to redefine them because label may change according to properties values. + $this->labelStatus = array(); + $this->labelStatusShort = array(); + + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { + global $langs; + //$langs->load("mymodule"); + $this->labelStatus[self::STATUS_UNPAID] = $langs->trans('BillStatusNotPaid'); + $this->labelStatus[self::STATUS_PAID] = $langs->trans('BillStatusPaid'); + if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) $this->labelStatus[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted"); + $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans('BillStatusNotPaid'); + $this->labelStatusShort[self::STATUS_PAID] = $langs->trans('BillStatusPaid'); + if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted"); + } + + $statusType = 'status1'; + if ($status == 0 && $alreadypaid <> 0) $statusType = 'status3'; + if ($status == 1) $statusType = 'status6'; + + return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); + } +} diff --git a/htdocs/salaries/document.php b/htdocs/salaries/document.php index dc86a274837..7bb8f67802e 100644 --- a/htdocs/salaries/document.php +++ b/htdocs/salaries/document.php @@ -7,6 +7,7 @@ * Copyright (C) 2011-2012 Juanjo Menent * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2015-2019 Alexandre Spangaro + * 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 @@ -33,7 +34,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; // Load translation files required by the page $langs->loadLangs(array("compta", "bills", "users", "salaries", "hrm")); @@ -62,7 +63,7 @@ if (!$sortorder) $sortorder = "ASC"; if (!$sortfield) $sortfield = "name"; -$object = new PaymentSalary($db); +$object = new Salary($db); $object->fetch($id, $ref); $upload_dir = $conf->salaries->dir_output.'/'.dol_sanitizeFileName($object->id); diff --git a/htdocs/salaries/info.php b/htdocs/salaries/info.php index c7a5090072e..72269faf630 100644 --- a/htdocs/salaries/info.php +++ b/htdocs/salaries/info.php @@ -2,6 +2,7 @@ /* Copyright (C) 2005-2015 Laurent Destailleur * Copyright (C) 2015 Charlie BENKE * Copyright (C) 2017-2019 Alexandre Spangaro + * 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 @@ -24,7 +25,7 @@ */ require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -46,7 +47,7 @@ $result = restrictedArea($user, 'salaries', '', '', ''); llxHeader("", $langs->trans("SalaryPayment")); -$object = new PaymentSalary($db); +$object = new Salary($db); $object->fetch($id); $object->info($id); diff --git a/htdocs/salaries/list.php b/htdocs/salaries/list.php index 119b224e76b..a776a2a8191 100644 --- a/htdocs/salaries/list.php +++ b/htdocs/salaries/list.php @@ -2,6 +2,7 @@ /* Copyright (C) 2011-2019 Alexandre Spangaro * Copyright (C) 2015-2016 Laurent Destailleur * Copyright (C) 2015 Jean-François Ferry + * 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 @@ -24,7 +25,7 @@ */ require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; if (!empty($conf->accounting->enabled)) { require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; @@ -82,10 +83,13 @@ if (!$sortorder) { $search_ref = GETPOST('search_ref', 'int'); $search_user = GETPOST('search_user', 'alpha'); $search_label = GETPOST('search_label', 'alpha'); -$search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int')); -$search_date_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int')); +$search_date_start_from = dol_mktime(0, 0, 0, GETPOST('search_date_start_frommonth', 'int'), GETPOST('search_date_start_fromday', 'int'), GETPOST('search_date_start_fromyear', 'int')); +$search_date_start_to = dol_mktime(23, 59, 59, GETPOST('search_date_start_tomonth', 'int'), GETPOST('search_date_start_today', 'int'), GETPOST('search_date_start_toyear', 'int')); +$search_date_end_from = dol_mktime(0, 0, 0, GETPOST('search_date_end_frommonth', 'int'), GETPOST('search_date_end_fromday', 'int'), GETPOST('search_date_end_fromyear', 'int')); +$search_date_end_to = dol_mktime(23, 59, 59, GETPOST('search_date_end_tomonth', 'int'), GETPOST('search_date_end_today', 'int'), GETPOST('search_date_end_toyear', 'int')); $search_amount = GETPOST('search_amount', 'alpha'); $search_account = GETPOST('search_account', 'int'); +$search_status = GETPOST('search_status', 'int'); $filtre = GETPOST("filtre", 'restricthtml'); @@ -160,10 +164,14 @@ if (empty($reshook)) { $search_ref = ""; $search_user = ""; $search_label = ""; - $search_date_start = ''; + $search_date_start_from = ''; + $search_date_start_to = ''; + $search_date_end_from = ''; + $search_date_end_to = ''; $search_date_end = ''; $search_amount = ""; $search_account = ''; + $search_status = ''; $search_type_id = ""; } if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') @@ -190,7 +198,7 @@ if (empty($reshook)) { */ $form = new Form($db); -$salstatic = new PaymentSalary($db); +$salstatic = new Salary($db); $userstatic = new User($db); $accountstatic = new Account($db); @@ -198,16 +206,18 @@ $now = dol_now(); //$help_url="EN:Module_BillOfMaterials|FR:Module_BillOfMaterials_FR|ES:Módulo_BillOfMaterials"; $help_url = ''; -$title = $langs->trans('SalariesPayments'); +$title = $langs->trans('Salaries'); $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.admin, u.salary as current_salary, u.fk_soc as fk_soc, u.statut as status,"; -$sql .= " s.rowid, s.fk_user, s.amount, s.salary, s.label, s.datep as datep, s.datev as datev, s.fk_typepayment as type, s.num_payment, s.fk_bank,"; +$sql .= " s.rowid, s.fk_account, s.paye, s.fk_user, s.amount, s.salary, s.label, s.datesp as datesp, s.dateep as dateep, s.fk_typepayment as type, s.num_payment, s.fk_bank,"; $sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel,"; -$sql .= " pst.code as payment_code"; -$sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as s"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid,"; +$sql .= " pst.code as payment_code,"; +$sql .= " SUM(ps.amount) as alreadypayed"; +$sql .= " FROM ".MAIN_DB_PREFIX."salary as s"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_salary as ps ON (ps.fk_salary = s.rowid) "; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON (s.fk_typepayment = pst.id) "; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account ba ON (ba.rowid = s.fk_account), "; +//$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_salary as ps ON ps.fk_salary = s.rowid, "; $sql .= " ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE u.rowid = s.fk_user"; $sql .= " AND s.entity IN (".getEntity('payment_salaries').")"; @@ -225,11 +235,11 @@ if ($search_user) { if ($search_label) { $sql .= natural_search(array('s.label'), $search_label); } -if ($search_date_start) { - $sql .= " AND s.datep >= '".$db->idate($search_date_start)."'"; +if (!empty($search_date_start_from) && !empty($search_date_start_to)) { + $sql .= " AND s.datesp BETWEEN '".$db->idate($search_date_start_from)."' AND '".$db->idate($search_date_start_to)."'"; } -if ($search_date_end) { - $sql .= " AND s.datep <= '".$db->idate($search_date_end)."'"; +if (!empty($search_date_end_from) && !empty($search_date_end_to)) { + $sql .= " AND s.dateep BETWEEN '".$db->idate($search_date_end_from)."' AND '".$db->idate($search_date_end_to)."'"; } if ($search_amount) { $sql .= natural_search("s.amount", $search_amount, 1); @@ -237,6 +247,9 @@ if ($search_amount) { if ($search_account > 0) { $sql .= " AND b.fk_account=".((int) $search_account); } +if ($search_status != '' && $search_status >= 0) { + $sql .= " AND s.paye = ".$db->escape($search_status); +} if ($filtre) { $filtre = str_replace(":", "=", $filtre); $sql .= " AND ".$filtre; @@ -244,6 +257,7 @@ if ($filtre) { if ($search_type_id) { $sql .= " AND s.fk_typepayment=".$search_type_id; } +$sql .= " GROUP BY s.rowid, s.amount, s.dateep, s.datesp, s.label, s.paye, pst.code"; $sql .= $db->order($sortfield, $sortorder); // Count total nb of records @@ -305,12 +319,22 @@ if ($search_label) { if ($search_account) { $param .= '&search_account='.urlencode($search_account); } -if ($search_date_start) { - $param .= '&search_date_startday='.urlencode(GETPOST('search_date_startday', 'int')).'&search_date_startmonth='.urlencode(GETPOST('search_date_startmonth', 'int')).'&search_date_startyear='.urlencode(GETPOST('search_date_startyear', 'int')); +if ($search_status != '' && $search_status != '-1') { + $param .= '&search_status='.urlencode($search_status); } -if ($search_date_end) { - $param .= '&search_date_endday='.urlencode(GETPOST('search_date_endday', 'int')).'&search_date_endmonth='.urlencode(GETPOST('search_date_endmonth', 'int')).'&search_date_endyear='.urlencode(GETPOST('search_date_endyear', 'int')); +if (!empty($search_date_start_from)) { + $param .= '&search_date_start_fromday='.urlencode(GETPOST('search_date_start_fromday')).'&search_date_start_frommonth='.urlencode(GETPOST('search_date_start_frommonth')).'&search_date_start_fromyear='.urlencode(GETPOST('search_date_start_fromyear')); } +if (!empty($search_date_start_to)) { + $param .= "&search_date_start_today=".urlencode(GETPOST('search_date_start_today'))."&search_date_start_tomonth=".urlencode(GETPOST('search_date_start_tomonth'))."&search_date_start_toyear=".urlencode(GETPOST('search_date_start_toyear')); +} +if (!empty($search_date_end_from)) { + $param .= '&search_date_end_fromday='.urlencode(GETPOST('search_date_end_fromday')).'&search_date_end_frommonth='.urlencode(GETPOST('search_date_end_frommonth')).'&search_date_end_fromyear='.urlencode(GETPOST('search_date_end_fromyear')); +} +if (!empty($search_date_end_to)) { + $param .= "&search_date_end_today=".urlencode(GETPOST('search_date_end_today'))."&search_date_end_tomonth=".urlencode(GETPOST('search_date_end_tomonth'))."&search_date_end_toyear=".urlencode(GETPOST('search_date_end_toyear')); +} + // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -367,18 +391,31 @@ print ''; -// Date payment + +// Date start print ''; print '
'; -print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); +print $langs->trans('From').' '; +print $form->selectDate($search_date_start_from ? $search_date_start_from : -1, 'search_date_start_from', 0, 0, 1); print '
'; print '
'; -print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); +print $langs->trans('to').' '; +print $form->selectDate($search_date_start_to ? $search_date_start_to : -1, 'search_date_start_to', 0, 0, 1); print '
'; print ''; -// Date value + +// Date End print ''; +print '
'; +print $langs->trans('From').' '; +print $form->selectDate($search_date_end_from ? $search_date_end_from : -1, 'search_date_end_from', 0, 0, 1); +print '
'; +print '
'; +print $langs->trans('to').' '; +print $form->selectDate($search_date_end_to ? $search_date_end_to : -1, 'search_date_end_to', 0, 0, 1); +print '
'; print ''; + // Type print ''; $form->select_types_paiements($search_type_id, 'search_type_id', '', 0, 1, 1, 16); @@ -392,6 +429,11 @@ if (!empty($conf->banque->enabled)) { // Amount print ''; +print ''; +$liststatus = array('0' => $langs->trans("Unpaid"), '1' => $langs->trans("Paid")); +print $form->selectarray('search_status', $liststatus, $search_status, 1); +print ''; + // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; @@ -411,15 +453,16 @@ print ''."\n"; // -------------------------------------------------------------------- print ''; print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $param, "", $sortfield, $sortorder); -print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.rowid", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.lastname", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "s.label", "", $param, 'class="left"', $sortfield, $sortorder); -print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "s.datep,s.rowid", "", $param, '', $sortfield, $sortorder, 'center '); -print_liste_field_titre("DateValue", $_SERVER["PHP_SELF"], "s.datev,s.rowid", "", $param, '', $sortfield, $sortorder, 'center '); + print_liste_field_titre("DateStart", $_SERVER["PHP_SELF"], "s.datesp,s.rowid", "", $param, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre("DateEnd", $_SERVER["PHP_SELF"], "s.dateep,s.rowid", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "type", "", $param, 'class="left"', $sortfield, $sortorder); if (!empty($conf->banque->enabled)) { print_liste_field_titre("BankAccount", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder); } -print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder); +print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder); +print_liste_field_titre('Status', $_SERVER["PHP_SELF"], "s.paye", '', $param, 'class="right"', $sortfield, $sortorder); // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; // Hook fields @@ -488,14 +531,14 @@ while ($i < ($limit ? min($num, $limit) : $num)) { $totalarray['nbfield']++; } - // Date payment - print ''.dol_print_date($db->jdate($obj->datep), 'day')."\n"; + // Date Start + print ''.dol_print_date($db->jdate($obj->datesp), 'day')."\n"; if (!$i) { $totalarray['nbfield']++; } - // Date value - print ''.dol_print_date($db->jdate($obj->datev), 'day')."\n"; + // Date End + print ''.dol_print_date($db->jdate($obj->dateep), 'day')."\n"; if (!$i) { $totalarray['nbfield']++; } @@ -509,7 +552,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) { // Account if (!empty($conf->banque->enabled)) { print ''; - if ($obj->fk_bank > 0) { + if ($obj->fk_account > 0) { //$accountstatic->fetch($obj->fk_bank); $accountstatic->id = $obj->bid; $accountstatic->ref = $obj->bref; @@ -523,7 +566,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) { $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1); } - $accountstatic->label = $obj->blabel; + //$accountstatic->label = $obj->blabel; print $accountstatic->getNomUrl(1); } else { print ' '; @@ -534,6 +577,8 @@ while ($i < ($limit ? min($num, $limit) : $num)) { } } + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalttcfield'; + // Amount print ''.price($obj->amount).''; if (!$i) { diff --git a/htdocs/salaries/paiement_salary.php b/htdocs/salaries/paiement_salary.php new file mode 100644 index 00000000000..6c0ae2066db --- /dev/null +++ b/htdocs/salaries/paiement_salary.php @@ -0,0 +1,347 @@ + + * 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/compta/paiement_charge.php + * \ingroup tax + * \brief Page to add payment of a tax + */ + +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->load("bills"); + +$chid = GETPOST("id", 'int'); +$action = GETPOST('action', 'alpha'); +$amounts = array(); + +// Security check +$socid = 0; +if ($user->socid > 0) +{ + $socid = $user->socid; +} + + +/* + * Actions + */ + +if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) +{ + $error = 0; + + if ($_POST["cancel"]) + { + $loc = DOL_URL_ROOT.'/salaries/card.php?id='.$chid; + header("Location: ".$loc); + exit; + } + + $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + + if (!$_POST["paiementtype"] > 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 (!empty($conf->banque->enabled) && !($_POST["accountid"] > 0)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors'); + $error++; + $action = 'create'; + } + + if (!$error) + { + $paymentid = 0; + + // Read possible payments + foreach ($_POST as $key => $value) + { + if (substr($key, 0, 7) == 'amount_') + { + $other_chid = substr($key, 7); + $amounts[$other_chid] = price2num($_POST[$key]); + } + } + + if (count($amounts) <= 0) + { + $error++; + setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors'); + $action = 'create'; + } + + if (!$error) + { + $db->begin(); + + // Create a line of payments + $paiement = new PaymentSalary($db); + $paiement->chid = $chid; + $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", 'none'); + $paiement->note_private = GETPOST("note", 'none'); + + 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='.$chid; + header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); + } + } + } +} + + +/* + * View + */ + +llxHeader(); + +$form = new Form($db); + + +// Formulaire de creation d'un paiement de charge +if ($action == 'create') +{ + $salary = new Salary($db); + $salary->fetch($chid); + $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"; + + if ($mesg) + { + print "
$mesg
"; + } + + print '
'; + print ''; + print ''; + print ''; + print ''; + + dol_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 = ".$chid; + $resql = $db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + $sumpaid = $obj->total; + $db->free(); + } + /*print ''; + print '';*/ + + print '"; + print ''; + + print '\n"; + print ''; + + print ''; + print ''; + print ''; + + // Number + print ''; + print ''."\n"; + + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Ref").''.$chid.'
'.$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, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (empty($_POST["remonth"]) ?-1 : $datepaye) : ''; + print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1); + print "
'.$langs->trans("PaymentMode").''; + $form->select_types_paiements(isset($_POST["paiementtype"]) ? $_POST["paiementtype"] : $salary->type_payment, "paiementtype"); + print "
'.$langs->trans('AccountToDebit').''; + $form->select_comptes(isset($_POST["accountid"]) ? $_POST["accountid"] : $salary->accountid, "accountid", 0, '', 1); // Show opend bank account list + print '
'.$langs->trans('Numero'); + print ' ('.$langs->trans("ChequeOrTransferNumber").')'; + print '
'.$langs->trans("Comments").'
'; + + dol_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; + if (!empty($conf->use_javascript_ajax)) + print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'"); + $remaintopay = $objp->amount - $sumpaid; + print ''; + print ''; + } + else + { + print '-'; + } + print "
'.$langs->trans("Total").':'.price($total_ttc).''.price($totalrecu).''.price($total_ttc - $totalrecu).' 
"; + + // Bouton Save payment + print '
'.$langs->trans("ClosePaidSalaryAutomatically"); + print '
'; + print '     '; + print ''; + print '
'; + + print "
\n"; +} + +llxFooter(); +$db->close(); diff --git a/htdocs/salaries/payment_salary/card.php b/htdocs/salaries/payment_salary/card.php new file mode 100644 index 00000000000..4d022b6704b --- /dev/null +++ b/htdocs/salaries/payment_salary/card.php @@ -0,0 +1,291 @@ + + * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2009 Regis Houssin + * 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/compta/payment_sc/card.php + * \ingroup facture + * \brief Onglet payment of a salary + * \remarks Fichier presque identique a fournisseur/paiement/card.php + */ + +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/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; +if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + +// Load translation files required by the page +$langs->loadLangs(array('bills', 'banks', 'companies')); + +// Security check +$id = GETPOST("id", 'int'); +$action = GETPOST('action', 'aZ09'); +$confirm = GETPOST('confirm'); +if ($user->socid) $socid = $user->socid; +// TODO ajouter regle pour restreindre acces paiement +//$result = restrictedArea($user, 'facture', $id,''); + +$object = new PaymentSalary($db); +if ($id > 0) +{ + $result = $object->fetch($id); + if (!$result) dol_print_error($db, 'Failed to get payment id '.$id); +} + + +/* + * Actions + */ + +// Delete payment +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->salaries->delete) +{ + $db->begin(); + + $result = $object->delete($user); + if ($result > 0) + { + $db->commit(); + header("Location: ".DOL_URL_ROOT."/salaries/payments.php"); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $db->rollback(); + } +} + +/* + * View + */ + +llxHeader(); + +$salary = new Salary($db); + +$form = new Form($db); + +$h = 0; + +$head[$h][0] = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$id; +$head[$h][1] = $langs->trans("SalaryPayment"); +$hselected = $h; +$h++; + +/*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id; +$head[$h][1] = $langs->trans("Info"); +$h++; +*/ + + +dol_fiche_head($head, $hselected, $langs->trans("SalaryPayment"), -1, 'payment'); + +/* + * Deletion confirmation of payment + */ +if ($action == 'delete') +{ + print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeleteSalary"), $langs->trans("ConfirmDeleteSalaryPayment"), 'confirm_delete', '', 0, 2); +} + +/* + * Validation confirmation of payment + */ +/* +if ($action == 'valide') +{ + $facid = $_GET['facid']; + print $form->formconfirm('card.php?id='.$object->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); + +} +*/ + + +$linkback = ''.$langs->trans("BackToList").''; + +dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', ''); + + +print '
'; +print '
'; + +print ''; + +// Ref +/*print ''; +print '';*/ + +// Date +print ''; + +// Mode +print ''; + +// Numero +print ''; + +// Montant +print ''; + +// Note +print ''; + +// Bank account +if (!empty($conf->banque->enabled)) +{ + if ($object->bank_account) + { + $bankline = new AccountLine($db); + $bankline->fetch($object->bank_line); + + print ''; + print ''; + print ''; + print ''; + } +} + +print '
'.$langs->trans('Ref').''; +print $form->showrefnav($object,'id','',1,'rowid','id'); +print '
'.$langs->trans('Date').''.dol_print_date($object->datep, 'day').'
'.$langs->trans('Mode').''.$langs->trans("PaymentType".$object->type_code).'
'.$langs->trans('Numero').''.$object->num_paiement.'
'.$langs->trans('Amount').''.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Note').''.nl2br($object->note).'
'.$langs->trans('BankTransactionLine').''; + print $bankline->getNomUrl(1, 0, 'showall'); + print '
'; + +print '
'; + +dol_fiche_end(); + + +/* + * List of salaries payed + */ + +$disable_delete = 0; +$sql = 'SELECT f.rowid as scid, f.label, f.paye, f.amount as sc_amount, ps.amount'; +$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps,'.MAIN_DB_PREFIX.'salary as f'; +$sql .= ' WHERE ps.fk_salary = f.rowid'; +$sql .= ' AND f.entity = '.$conf->entity; +$sql .= ' AND ps.rowid = '.$object->id; + +dol_syslog("payment_salary/card.php", LOG_DEBUG); +$resql = $db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + + $i = 0; + $total = 0; + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + if ($num > 0) + { + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + print ''; + // Ref + print '\n"; + // Type + print '\n"; + // Label + print ''; + // Expected to pay + print ''; + // Status + print ''; + // Amount payed + print ''; + print "\n"; + if ($objp->paye == 1) // If at least one invoice is paid, disable delete + { + $disable_delete = 1; + } + $total = $total + $objp->amount; + $i++; + } + } + + + print "
'.$langs->trans('Salary').''.$langs->trans('Type').''.$langs->trans('Label').''.$langs->trans('ExpectedToPay').''.$langs->trans('Status').''.$langs->trans('PayedByThisPayment').'
'; + $salary->fetch($objp->scid); + print $salary->getNomUrl(1); + print "'; + print $salary->type_label; + /*print $salary->type;*/ + print "'.$objp->label.''.price($objp->sc_amount).''.$salary->getLibStatut(4, $objp->amount).''.price($objp->amount).'
\n"; + $db->free($resql); +} +else +{ + dol_print_error($db); +} + + + +/* + * Boutons Actions + */ +print '
'; + +/* +if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) +{ + if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '') + { + if ($user->rights->facture->paiement) + { + print ''.$langs->trans('Valid').''; + } + } +} +*/ + +if ($action == '') +{ + if ($user->rights->salaries->delete) + { + if (!$disable_delete) + { + print ''.$langs->trans('Delete').''; + } + else + { + print ''.$langs->trans('Delete').''; + } + } +} + +print '
'; + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/salaries/payments.php b/htdocs/salaries/payments.php new file mode 100644 index 00000000000..a5b62143d48 --- /dev/null +++ b/htdocs/salaries/payments.php @@ -0,0 +1,222 @@ + + * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2011-2016 Alexandre Spangaro + * Copyright (C) 2011-2014 Juanjo Menent + * Copyright (C) 2015 Jean-François Ferry + * 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/compta/sociales/payments.php + * \ingroup compta + * \brief Page to list payments of special expenses + */ + +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.'/core/lib/date.lib.php'; + +// Load translation files required by the page +$langs->loadLangs(array('compta', 'bills')); + +// Security check +if ($user->socid) $socid = $user->socid; +$result = restrictedArea($user, 'tax|salaries', '', '', 'charges|'); + +$mode = GETPOST("mode", 'alpha'); +$year = GETPOST("year", 'int'); +$filtre = GETPOST("filtre", 'alpha'); +if (!$year && $mode != 'sconly') { $year = date("Y", time()); } + +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (!$sortfield) $sortfield = "pc.datep"; +if (!$sortorder) $sortorder = "DESC"; + + +/* + * View + */ + +$payment_salary_static = new PaymentSalary($db); +$sal_static = new Salary($db); + +llxHeader('', $langs->trans("SalariesArea")); + +$title = $langs->trans("SalariesPayments"); +if ($mode == 'sconly') $title = $langs->trans("PaymentsSalaries"); + +$param = ''; +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage; +if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; +if ($mode == 'sconly') $param = '&mode=sconly'; +if ($sortfield) $param .= '&sortfield='.$sortfield; +if ($sortorder) $param .= '&sortorder='.$sortorder; + + +print '
'; +if ($optioncss != '') print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'title_accountancy', 0, '', '', $limit); + +if ($year) $param .= '&year='.$year; + +// Localtax +if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") +{ + $j = 1; + $numlt = 3; +} +elseif ($mysoc->localtax1_assuj == "1") +{ + $j = 1; + $numlt = 2; +} +elseif ($mysoc->localtax2_assuj == "1") +{ + $j = 2; + $numlt = 3; +} +else +{ + $j = 0; + $numlt = 0; +} + +// Payment Salary +if (!empty($conf->salaries->enabled) && !empty($user->rights->salaries->read)) +{ + if (!$mode || $mode != 'sconly') + { + $sal = new Salary($db); + + $sql = "SELECT ps.rowid as payment_id, ps.amount, s.rowid as salary_id, s.label, ps.datep as datep, s.datesp, s.dateep, s.amount as salary, u.salary as current_salary, pct.code as payment_code"; + $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as ps"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as s ON (s.rowid = ps.fk_salary)"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON (u.rowid = s.fk_user)"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON ps.fk_typepaiement = pct.id"; + $sql .= " WHERE s.entity IN (".getEntity('user').")"; + /* if ($year > 0) + { + $sql .= " AND (s.datesp between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'"; + $sql .= " OR s.dateep between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."')"; + }*/ + if (preg_match('/^s\./', $sortfield) + || preg_match('/^pct\./', $sortfield) + || preg_match('/^ps\./', $sortfield)) $sql .= $db->order($sortfield, $sortorder); + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + $total = 0; + print ''; + print ''; + print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "s.rowid", "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "ps.datep", "", $param, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("Salary", $_SERVER["PHP_SELF"], "s.rowid", "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("DateStart", $_SERVER["PHP_SELF"], "s.datesp", "", $param, 'width="140px"', $sortfield, $sortorder); + print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "s.dateep", "", $param, 'width="140px"', $sortfield, $sortorder); + print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "s.label", "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder); + print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder); + print "\n"; + + while ($i < $num) + { + $obj = $db->fetch_object($result); + + $total = $total + $obj->amount; + + print ''; + + // Ref payment + $payment_salary_static->id = $obj->payment_id; + $payment_salary_static->ref = $obj->payment_id; + print '\n"; + + print '\n"; + + // Type payment + print ''; + + print ''; + + // Date début salaire + print ''."\n"; + + // Date fin salaire + print ''."\n"; + + print "\n"; + + print '"; + print '"; + print "\n"; + + $i++; + } + print ''; + print ''; // A total here has no sense + print ''; + print ''; + print ''; + print ''; + print ''; + print '"; + print ""; + + print "
'.$payment_salary_static->getNomUrl(1)."'.dol_print_date($db->jdate($obj->datep), 'day')."'; + if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' '; + print $obj->num_payment.''; + $sal_static->id = $obj->salary_id; + $sal_static->ref = $obj->salary_id; + $sal_static->label = $obj->label; + print $sal_static->getNomUrl(1, '20'); + print ''.dol_print_date($db->jdate($obj->datesp), 'day').''.dol_print_date($db->jdate($obj->dateep), 'day').'".$obj->label."'.($obj->salary ?price($obj->salary) : '')."'.price($obj->amount)."
'.$langs->trans("Total").'     '.price($total)."
"; + $db->free($result); + + print "
"; + } + else + { + dol_print_error($db); + } + } +} + +print '
'; + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/salaries/stats/index.php b/htdocs/salaries/stats/index.php index 99b2fd9042f..b97bb1c0a95 100644 --- a/htdocs/salaries/stats/index.php +++ b/htdocs/salaries/stats/index.php @@ -1,6 +1,7 @@ * Copyright (C) 2018 Fidesio + * 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 @@ -27,7 +28,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; require_once DOL_DOCUMENT_ROOT.'/salaries/class/salariesstats.class.php'; // Load translation files required by the page -$langs->loadLangs(array("salaries", "companies")); +$langs->loadLangs(array("salaries", "companies", "bills")); $WIDTH = DolGraph::getDefaultGraphSizeForStats('width'); $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height'); diff --git a/htdocs/user/bank.php b/htdocs/user/bank.php index 20369e37d69..8e6d6945845 100644 --- a/htdocs/user/bank.php +++ b/htdocs/user/bank.php @@ -6,6 +6,7 @@ * Copyright (C) 2013 Peter Fontaine * Copyright (C) 2015-2016 Marcos García * Copyright (C) 2015 Alexandre Spangaro + * 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 @@ -34,7 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/userbankaccount.class.php'; if (!empty($conf->holiday->enabled)) require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; if (!empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; -if (!empty($conf->salaries->enabled)) require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; +if (!empty($conf->salaries->enabled)) require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; // Load translation files required by page $langs->loadLangs(array('companies', 'commercial', 'banks', 'bills', 'trips', 'holiday', 'salaries')); @@ -340,7 +341,7 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco $user->rights->salaries->read && (in_array($object->id, $childids) || $object->id == $user->id) ) { - $salary = new PaymentSalary($db); + $salary = new Salary($db); $sql = "SELECT ps.rowid, ps.datesp, ps.dateep, ps.amount"; $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as ps";