diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 3fa7d7a1110..cb3afb95f5a 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -63,7 +63,7 @@ $langs->load('bills'); $langs->load('donations'); $langs->load("accountancy"); $langs->load("trips"); -$langs->load("hrm"); +$langs->load("salaries"); // Multi journal $id_journal = GETPOST('id_journal', 'int'); @@ -112,7 +112,7 @@ $idpays = $p[0]; $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,"; $sql .= " ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,"; $sql .= " soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, bu1.type as typeop,"; -$sql .= " u.accountancy_code, u.rowid as userid, u.lastname as name, u.firstname as firstname, bu2.type as typeop"; +$sql .= " u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, bu2.type as typeop"; $sql .= " FROM " . MAIN_DB_PREFIX . "bank as b"; $sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'"; @@ -166,7 +166,7 @@ if ($result) { // one line for bank jounral = tabbq // one line for thirdparty journal = tabtp $i = 0; - while ( $i < $num ) + while ( $i < $num ) { $obj = $db->fetch_object($result); @@ -187,6 +187,7 @@ if ($result) { $tabuser[$obj->rowid] = array ( 'id' => $obj->userid, + 'name' => dolGetFirstLastname($obj->firstname, $obj->lastname), 'lastname' => $obj->lastname, 'firstname' => $obj->firstname, 'accountancy_code' => $compta_user, @@ -209,11 +210,11 @@ if ($result) { // Now loop on each link of record in bank. foreach ( $links as $key => $val ) { - if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert', 'payment_donation'))) // So we excluded 'company' here - { - // We save tabtype for a future use, to remember what kind of payment it is - $tabtype[$obj->rowid] = $links[$key]['type']; - } + if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert', 'payment_donation', 'payment_salary'))) // So we excluded 'company' here + { + // We save tabtype for a future use, to remember what kind of payment it is + $tabtype[$obj->rowid] = $links[$key]['type']; + } if ($links[$key]['type'] == 'payment') { $paymentstatic->id = $links[$key]['url_id']; @@ -280,7 +281,7 @@ if ($result) { $paymentsalstatic->ref = $links[$key]['url_id']; $paymentsalstatic->label = $links[$key]['label']; $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2); - // $tabtp[$obj->rowid][$account_employee] += $obj->amount; + $tabpay[$obj->rowid]["paymentsalid"] = $paymentsalstatic->id; } else if ($links[$key]['type'] == 'payment_expensereport') { $paymentexpensereportstatic->id = $links[$key]['url_id']; $paymentexpensereportstatic->fk_expensereport = $links[$key]['url_id']; @@ -295,7 +296,7 @@ if ($result) { $tabbq[$obj->rowid][$compta_bank] += $obj->amount; - + // Check account number is ok /*if ($action == 'writebookkeeping') // Make test now in such a case { @@ -314,7 +315,7 @@ if ($result) { setEventMessages($langs->trans('ErrorAccountancyCodeOnThirdPartyNotDefined'), null, 'errors'); } }*/ - + // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount; $i ++; @@ -344,7 +345,7 @@ if (! $error && $action == 'writebookkeeping') { if (! $errorforline) { // Line into bank account - foreach ( $tabbq[$key] as $k => $mt ) + foreach ( $tabbq[$key] as $k => $mt ) { if ($mt) { $bookkeeping = new BookKeeping($db); @@ -362,10 +363,10 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->code_journal = $journal; $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_create = $now; - + if ($tabtype[$key] == 'payment') { $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; - + $sqlmid = 'SELECT fac.facnumber'; $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac"; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; @@ -379,7 +380,7 @@ if (! $error && $action == 'writebookkeeping') { } } else if ($tabtype[$key] == 'payment_supplier') { $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; - + $sqlmid = 'SELECT facf.ref_supplier, facf.ref'; $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf"; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; @@ -393,7 +394,7 @@ if (! $error && $action == 'writebookkeeping') { } } else if ($tabtype[$key] == 'payment_expensereport') { $bookkeeping->code_tiers = $tabuser[$key]['accountancy_code']; - + $sqlmid = 'SELECT e.ref'; $sqlmid .= " FROM " . MAIN_DB_PREFIX . "expensereport as e"; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_expensereport as payer ON payer.fk_expensereport=e.rowid"; @@ -404,14 +405,18 @@ if (! $error && $action == 'writebookkeeping') { $objmid = $db->fetch_object($resultmid); $bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport } - } else if ($tabtype[$key] == 'payment_vat') { - $bookkeeping->code_tiers = ''; - $bookkeeping->doc_ref = $langs->trans("PaymentVat") . ' (' . $val["paymentvatid"] . ')'; // Rowid of vat payment - } else if ($tabtype[$key] == 'payment_donation') { - $bookkeeping->code_tiers = ''; - $bookkeeping->doc_ref = $langs->trans("Donation") . ' (' . $val["paymentdonationid"] . ')'; // Rowid of donation - } - + } else if ($tabtype[$key] == 'payment_vat') { + $bookkeeping->code_tiers = ''; + $bookkeeping->doc_ref = $langs->trans("PaymentVat") . ' (' . $val["paymentvatid"] . ')'; // Rowid of vat payment + } else if ($tabtype[$key] == 'payment_donation') { + $bookkeeping->code_tiers = ''; + $bookkeeping->doc_ref = $langs->trans("Donation") . ' (' . $val["paymentdonationid"] . ')'; // Rowid of donation + } else if ($tabtype[$key] == 'payment_salary') { + $bookkeeping->code_tiers = ''; + $bookkeeping->label_compte = $tabuser[$key]['name']; + $bookkeeping->doc_ref = $langs->trans("SalaryPayment") . ' (' . $val["paymentsalid"] . ')'; // Ref of salary payment + } + $result = $bookkeeping->create($user); if ($result < 0) { if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists @@ -451,7 +456,7 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->code_journal = $journal; $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_create = $now; - + if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution $bookkeeping->code_tiers = ''; $bookkeeping->numero_compte = $k; @@ -481,26 +486,31 @@ if (! $error && $action == 'writebookkeeping') { $objmid = $db->fetch_object($resultmid); $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')'; } - $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; - $bookkeeping->numero_compte = $k; - } else if ($tabtype[$key] == 'payment_vat') { - $bookkeeping->code_tiers = ''; - $bookkeeping->numero_compte = $k; - $bookkeeping->doc_ref = $langs->trans("PaymentVat") . ' (' . $val["paymentvatid"] . ')'; // Rowid of vat - } else if ($tabtype[$key] == 'payment_donation') { - $bookkeeping->code_tiers = ''; - $bookkeeping->numero_compte = $k; - $bookkeeping->doc_ref = $langs->trans("Donation") . ' (' . $val["paymentdonationid"] . ')'; // Rowid of donation - } else if ($tabtype[$key] == 'banktransfert') { - $bookkeeping->code_tiers = ''; - $bookkeeping->numero_compte = $k; + $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; + $bookkeeping->numero_compte = $k; + } else if ($tabtype[$key] == 'payment_vat') { + $bookkeeping->code_tiers = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->doc_ref = $langs->trans("PaymentVat") . ' (' . $val["paymentvatid"] . ')'; // Rowid of vat + } else if ($tabtype[$key] == 'payment_donation') { + $bookkeeping->code_tiers = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->doc_ref = $langs->trans("Donation") . ' (' . $val["paymentdonationid"] . ')'; // Rowid of donation + } else if ($tabtype[$key] == 'payment_salary') { + $bookkeeping->code_tiers = $tabuser[$key]['accountancy_code']; + $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + $bookkeeping->label_compte = $tabuser[$key]['name']; + $bookkeeping->doc_ref = $langs->trans("SalaryPayment") . ' (' . $val["paymentsalid"] . ')'; // Rowid of salary payment + } else if ($tabtype[$key] == 'banktransfert') { + $bookkeeping->code_tiers = ''; + $bookkeeping->numero_compte = $k; } else { // FIXME Should be a temporary account ??? $bookkeeping->doc_ref = $k; //$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; $bookkeeping->numero_compte = 'CodeNotDef'; } - + $result = $bookkeeping->create($user); if ($result < 0) { if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists @@ -519,7 +529,7 @@ if (! $error && $action == 'writebookkeeping') { } } } - + if (! $errorforline) { $db->commit(); @@ -541,7 +551,7 @@ if (! $error && $action == 'writebookkeeping') { { setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); } - + $action = ''; } @@ -582,7 +592,7 @@ if ($action == 'export_csv') { if ($reflabel == '(ExpenseReportPayment)') { $reflabel = $langs->trans('Employee'); } - + $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; @@ -728,6 +738,7 @@ if (empty($action) || $action == 'view') { $expensereportstatic = new ExpenseReport($db); $vatstatic = new Tva($db); $donationstatic = new Don($db); + $salarystatic = new PaymentSalary($db); llxHeader('', $langs->trans("FinanceJournal")); @@ -750,7 +761,7 @@ if (empty($action) || $action == 'view') { print '