--- /tmp/dsg/dolibarr/htdocs/accountancy/journal/github_19.0.3_bankjournal.php +++ /tmp/dsg/dolibarr/htdocs/accountancy/journal/client_bankjournal.php @@ -7,2 +7 @@ - * Copyright (C) 2013-2022 Open-DSI - * Copyright (C) 2013-2023 Alexandre Spangaro + * Copyright (C) 2013-2019 Alexandre Spangaro @@ -11 +10 @@ - * Copyright (C) 2017-2023 Frédéric France + * Copyright (C) 2017-2018 Frédéric France @@ -14 +12,0 @@ - * Copyright (C) 2021 Gauthier VERDOL @@ -78,3 +76 @@ -if ($in_bookkeeping == '') { - $in_bookkeeping = 'notyet'; -} +if ($in_bookkeeping == '') $in_bookkeeping = 'notyet'; @@ -87 +83 @@ -if (!isModEnabled('accounting')) { +if ($user->socid > 0 && empty($id_journal)) @@ -89,7 +84,0 @@ -} -if ($user->socid > 0) { - accessforbidden(); -} -if (!$user->hasRight('accounting', 'mouvements', 'lire')) { - accessforbidden(); -} @@ -103,0 +93,8 @@ +$year_current = strftime("%Y", dol_now()); +$pastmonth = strftime("%m", dol_now()) - 1; +$pastmonthyear = $year_current; +if ($pastmonth == 0) { + $pastmonth = 12; + $pastmonthyear--; +} + @@ -107,16 +104,2 @@ -if (empty($date_startmonth)) { - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_start = $dates['date_start']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} -if (empty($date_endmonth)) { - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_end = $dates['date_end']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} - -if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) { // We define date_start and date_end, only if we did not submit the form +if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) // We define date_start and date_end, only if we did not submit the form +{ @@ -127 +110 @@ -$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.amount_main_currency, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, b.fk_account,"; +$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, b.fk_account,"; @@ -129,10 +112,2 @@ -$sql .= " soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,"; -if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { - $sql .= " spe.accountancy_code_customer as code_compta,"; - $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; -} else { - $sql .= " soc.code_compta,"; - $sql .= " soc.code_compta_fournisseur,"; -} -$sql .= " u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, u.statut as userstatus,"; -$sql .= " bu2.type as typeop_user,"; +$sql .= " soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, soc.email as email, bu1.type as typeop_company,"; +$sql .= " u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, u.email as useremail, bu2.type as typeop_user,"; @@ -147,3 +121,0 @@ -if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = soc.rowid AND spe.entity = " . ((int) $conf->entity); -} @@ -151,3 +123,3 @@ -$sql .= " WHERE ba.fk_accountancy_journal=".((int) $id_journal); -$sql .= ' AND b.amount <> 0 AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy -if ($date_start && $date_end) { +$sql .= " WHERE ba.fk_accountancy_journal=".$id_journal; +$sql .= ' AND b.amount != 0 AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy +if ($date_start && $date_end) @@ -155,5 +126,0 @@ -} -// Define begin binding date -if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) { - $sql .= " AND b.dateo >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'"; -} @@ -161 +128,2 @@ -if ($in_bookkeeping == 'already') { +if ($in_bookkeeping == 'already') +{ @@ -164 +132,2 @@ -if ($in_bookkeeping == 'notyet') { +if ($in_bookkeeping == 'notyet') +{ @@ -178 +147 @@ -$paymentvatstatic = new Tva($db); +$paymentvatstatic = new TVA($db); @@ -197 +166 @@ -//print $sql; + @@ -205,7 +174,7 @@ - $account_supplier = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER', 'NotDefined'); // NotDefined is a reserved word - $account_customer = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER', 'NotDefined'); // NotDefined is a reserved word - $account_employee = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', 'NotDefined'); // NotDefined is a reserved word - $account_pay_vat = getDolGlobalString('ACCOUNTING_VAT_PAY_ACCOUNT', 'NotDefined'); // NotDefined is a reserved word - $account_pay_donation = getDolGlobalString('DONATION_ACCOUNTINGACCOUNT', 'NotDefined'); // NotDefined is a reserved word - $account_pay_subscription = getDolGlobalString('ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT', 'NotDefined'); // NotDefined is a reserved word - $account_transfer = getDolGlobalString('ACCOUNTING_ACCOUNT_TRANSFER_CASH', 'NotDefined'); // NotDefined is a reserved word + $account_supplier = (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER != "") ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : 'NotDefined'); // NotDefined is a reserved word + $account_customer = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER != "") ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : 'NotDefined'); // NotDefined is a reserved word + $account_employee = (!empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : 'NotDefined'); // NotDefined is a reserved word + $account_pay_vat = (!empty($conf->global->ACCOUNTING_VAT_PAY_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT : 'NotDefined'); // NotDefined is a reserved word + $account_pay_donation = (!empty($conf->global->DONATION_ACCOUNTINGACCOUNT) ? $conf->global->DONATION_ACCOUNTINGACCOUNT : 'NotDefined'); // NotDefined is a reserved word + $account_pay_subscription = (!empty($conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT) ? $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT : 'NotDefined'); // NotDefined is a reserved word + $account_transfer = (!empty($conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH) ? $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH : 'NotDefined'); // NotDefined is a reserved word @@ -221 +190 @@ - // Loop on each line into the llx_bank table. For each line, we should get: + // Loop on each line into llx_bank table. For each line, we should get: @@ -225 +193,0 @@ - // Note: tabcompany is used to store the subledger account @@ -227 +195,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -233,6 +202,2 @@ - if ($obj->label == '(SupplierInvoicePayment)' || $obj->label == '(SupplierInvoicePaymentBack)') { - $lineisapurchase = 1; - } - if ($obj->label == '(CustomerInvoicePayment)' || $obj->label == '(CustomerInvoicePaymentBack)') { - $lineisasale = 1; - } + if ($obj->label == '(SupplierInvoicePayment)' || $obj->label == '(SupplierInvoicePaymentBack)') $lineisapurchase = 1; + if ($obj->label == '(CustomerInvoicePayment)' || $obj->label == '(CustomerInvoicePaymentBack)') $lineisasale = 1; @@ -240,11 +205,9 @@ - if ($lineisapurchase < 0) { - if ($obj->typeop_payment_supplier == 'payment_supplier') { - $lineisapurchase = 1; - } - } - if ($lineisasale < 0) { - if ($obj->typeop_payment == 'payment') { - $lineisasale = 1; - } - } - //var_dump($obj->type_payment); //var_dump($obj->type_payment_supplier); + if ($lineisapurchase < 0) + { + if ($obj->typeop_payment_supplier == 'payment_supplier') $lineisapurchase = 1; + } + if ($lineisasale < 0) + { + if ($obj->typeop_payment == 'payment') $lineisasale = 1; + } + //var_dump($obj->type_payment); var_dump($obj->type_payment_supplier); @@ -258 +221 @@ - if ($lineisapurchase > 0) { + if ($lineisapurchase > 0) @@ -260,2 +223 @@ - } - if ($lineisasale > 0) { + if ($lineisasale > 0) @@ -263 +224,0 @@ - } @@ -266,4 +227,4 @@ - 'id' => $obj->socid, - 'name' => $obj->name, - 'code_compta' => $compta_soc, - 'email' => $obj->email + 'id' => $obj->socid, + 'name' => $obj->name, + 'code_compta' => $compta_soc, + 'email' => $obj->email @@ -273,3 +234 @@ - // $obj->accountancy_code is the accountancy_code of table u=user (but it is defined only if - // a link with type 'user' exists and user as a subledger account) - $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code : ''); + $compta_user = (!empty($obj->accountancy_code) ? $obj->accountancy_code : $account_employee); @@ -278,7 +237,6 @@ - 'id' => $obj->userid, - 'name' => dolGetFirstLastname($obj->firstname, $obj->lastname), - 'lastname' => $obj->lastname, - 'firstname' => $obj->firstname, - 'email' => $obj->useremail, - 'accountancy_code' => $compta_user, - 'status' => $obj->userstatus + 'id' => $obj->userid, + 'name' => dolGetFirstLastname($obj->firstname, $obj->lastname), + 'lastname' => $obj->lastname, + 'firstname' => $obj->firstname, + 'email' => $obj->useremail, + 'accountancy_code' => $compta_user @@ -288 +246 @@ - $tabpay[$obj->rowid]["date"] = $db->jdate($obj->do); + $tabpay[$obj->rowid]["date"] = $obj->do; @@ -294 +251,0 @@ - $reg = array(); @@ -300,2 +256,0 @@ - - // Load of url links to the line into llx_bank (so load llx_bank_url) @@ -302,0 +258,4 @@ + + //var_dump($i); + //var_dump($tabpay); + //var_dump($tabcompany); @@ -309,6 +267,0 @@ - $amounttouse = $obj->amount; - if (!empty($obj->amount_main_currency)) { - // If $obj->amount_main_currency is set, it means that $obj->amount is not in same currency, we must use $obj->amount_main_currency - $amounttouse = $obj->amount_main_currency; - } - @@ -317,21 +270 @@ - // Test if entry is for a social contribution, salary or expense report. - // In such a case, we will ignore the bank url line for user - $is_sc = false; - $is_salary = false; - $is_expensereport = false; - foreach ($links as $v) { - if ($v['type'] == 'sc') { - $is_sc = true; - break; - } - if ($v['type'] == 'payment_salary') { - $is_salary = true; - break; - } - if ($v['type'] == 'payment_expensereport') { - $is_expensereport = true; - break; - } - } - - // Now loop on each link of record in bank (code similar to bankentries_list.php) + // Now loop on each link of record in bank. @@ -339,6 +272,2 @@ - if ($links[$key]['type'] == 'user' && !$is_sc && !$is_salary && !$is_expensereport) { - // We must avoid as much as possible this "continue". If we want to jump to next loop, it means we don't want to process - // the case the link is user (often because managed by hard coded code into another link), and we must avoid this. - continue; - } - if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert', 'payment_donation', 'member', 'payment_loan', 'payment_salary', 'payment_various'))) { + if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert', 'payment_donation', 'member', 'payment_loan', 'payment_salary', 'payment_various'))) + { @@ -350,2 +279,5 @@ - } elseif (in_array($links[$key]['type'], array('company', 'user'))) { - if ($tabpay[$obj->rowid]['type'] == 'unknown') { + } + elseif (in_array($links[$key]['type'], array('company', 'user'))) + { + if ($tabpay[$obj->rowid]['type'] == 'unknown') + { @@ -357 +288,0 @@ - // Special case to ask later to add more request to get information for old links without company link. @@ -377,7 +308 @@ - if ($compta_soc) { - if (empty($tabtp[$obj->rowid][$compta_soc])) { - $tabtp[$obj->rowid][$compta_soc] = $amounttouse; - } else { - $tabtp[$obj->rowid][$compta_soc] += $amounttouse; - } - } + if ($compta_soc) $tabtp[$obj->rowid][$compta_soc] += $obj->amount; @@ -390,23 +315,3 @@ - $userstatic->statut = $tabuser[$obj->rowid]['status']; - $userstatic->status = $tabuser[$obj->rowid]['status']; - $userstatic->accountancy_code = $tabuser[$obj->rowid]['accountancy_code']; - // For a payment of social contribution, we have a link sc + user. - // but we already fill the $tabpay[$obj->rowid]["soclib"] in the line 'sc'. - // If we fill it here to, we must concat - if ($userstatic->id > 0) { - if ($is_sc) { - $tabpay[$obj->rowid]["soclib"] .= ' '.$userstatic->getNomUrl(1, 'accountancy', 0); - } else { - $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, 'accountancy', 0); - } - } else { - $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen, but happens with old data when id of user was not saved on expense report payment. - } - - if ($compta_user) { - if ($is_sc) { - //$tabcompany[$obj->rowid][$compta_user] += $amounttouse; - } else { - $tabtp[$obj->rowid][$compta_user] += $amounttouse; - } - } + if ($userstatic->id > 0) $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, '', 30); + else $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen, but happens with old data when id of user was not saved on expense report payment. + if ($compta_user) $tabtp[$obj->rowid][$compta_user] += $obj->amount; @@ -418 +322,0 @@ - $reg = array(); @@ -420 +324 @@ - if ($reg[1] == 'socialcontribution') { + if ($reg[1] == 'socialcontribution') @@ -422 +325,0 @@ - } @@ -431,8 +334,6 @@ - // Retrieve the accounting code of the social contribution of the payment from link of payment. - // Note: We have the social contribution id, it can be faster to get accounting code from social contribution id. - $sqlmid = "SELECT cchgsoc.accountancy_code"; - $sqlmid .= " FROM ".MAIN_DB_PREFIX."c_chargesociales cchgsoc"; - $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."chargesociales as chgsoc ON chgsoc.fk_type = cchgsoc.id"; - $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."paiementcharge as paycharg ON paycharg.fk_charge = chgsoc.rowid"; - $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."bank_url as bkurl ON bkurl.url_id=paycharg.rowid AND bkurl.type = 'payment_sc'"; - $sqlmid .= " WHERE bkurl.fk_bank = ".((int) $obj->rowid); + $sqlmid = 'SELECT cchgsoc.accountancy_code'; + $sqlmid .= " FROM ".MAIN_DB_PREFIX."c_chargesociales cchgsoc "; + $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id"; + $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid"; + $sqlmid .= " INNER JOIN ".MAIN_DB_PREFIX."bank_url as bkurl ON bkurl.url_id=paycharg.rowid"; + $sqlmid .= " WHERE bkurl.fk_bank=".$obj->rowid; @@ -444 +345 @@ - $tabtp[$obj->rowid][$objmid->accountancy_code] += $amounttouse; + $tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount; @@ -452 +353 @@ - $tabtp[$obj->rowid][$account_pay_donation] += $amounttouse; + $tabtp[$obj->rowid][$account_pay_donation] += $obj->amount; @@ -460 +361 @@ - $tabtp[$obj->rowid][$account_pay_subscription] += $amounttouse; + $tabtp[$obj->rowid][$account_pay_subscription] += $obj->amount; @@ -467 +368 @@ - $tabtp[$obj->rowid][$account_pay_vat] += $amounttouse; + $tabtp[$obj->rowid][$account_pay_vat] += $obj->amount; @@ -474,38 +374,0 @@ - - // This part of code is no more required. it is here to solve case where a link were missing (ith v14.0.0) and keep writing in accountancy complete. - // Note: A better way to fix this is to delete payment of salary and recreate it, or to fix the bookkeeping table manually after. - if (getDolGlobalString('ACCOUNTANCY_AUTOFIX_MISSING_LINK_TO_USER_ON_SALARY_BANK_PAYMENT')) { - $tmpsalary = new Salary($db); - $tmpsalary->fetch($paymentsalstatic->id); - $tmpsalary->fetch_user($tmpsalary->fk_user); - - $userstatic->id = $tmpsalary->user->id; - $userstatic->name = $tmpsalary->user->name; - $userstatic->email = $tmpsalary->user->email; - $userstatic->firstname = $tmpsalary->user->firstname; - $userstatic->lastname = $tmpsalary->user->lastname; - $userstatic->statut = $tmpsalary->user->statut; - $userstatic->accountancy_code = $tmpsalary->user->accountancy_code; - - if ($userstatic->id > 0) { - $tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, 'accountancy', 0); - } else { - $tabpay[$obj->rowid]["soclib"] = '???'; // Should not happen - } - - if (empty($obj->typeop_user)) { // Add test to avoid to add amount twice if a link already exists also on user. - $compta_user = $userstatic->accountancy_code; - if ($compta_user) { - $tabtp[$obj->rowid][$compta_user] += $amounttouse; - $tabuser[$obj->rowid] = array( - 'id' => $userstatic->id, - 'name' => dolGetFirstLastname($userstatic->firstname, $userstatic->lastname), - 'lastname' => $userstatic->lastname, - 'firstname' => $userstatic->firstname, - 'email' => $userstatic->email, - 'accountancy_code' => $compta_user, - 'status' => $userstatic->statut - ); - } - } - } @@ -524,3 +387,3 @@ - $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account : ''); // NotDefined is a reserved word - $tabpay[$obj->rowid]["account_various"] = $account_various; - $tabtp[$obj->rowid][$account_subledger] += $amounttouse; + $account_subledger = (!empty($paymentvariousstatic->subledger_account) ? $paymentvariousstatic->subledger_account : ''); // NotDefined is a reserved word + $tabpay[$obj->rowid]["account_various"] = $account_various; + $tabtp[$obj->rowid][$account_subledger] += $obj->amount; @@ -533 +396 @@ - //$tabtp[$obj->rowid][$account_pay_loan] += $amounttouse; + //$tabtp[$obj->rowid][$account_pay_loan] += $obj->amount; @@ -536 +399 @@ - $sqlmid .= ' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.((int) $obj->rowid); + $sqlmid .= ' WHERE l.rowid = pl.fk_loan AND pl.fk_bank = '.$obj->rowid; @@ -549 +412 @@ - $tabtp[$obj->rowid][$account_transfer] += $amounttouse; + $tabtp[$obj->rowid][$account_transfer] += $obj->amount; @@ -556,5 +419 @@ - if (empty($tabbq[$obj->rowid][$compta_bank])) { - $tabbq[$obj->rowid][$compta_bank] = $amounttouse; - } else { - $tabbq[$obj->rowid][$compta_bank] += $amounttouse; - } + $tabbq[$obj->rowid][$compta_bank] += $obj->amount; @@ -564 +423,2 @@ - if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid]['withdraw'])) { // If we dont find 'company' link because it is an old 'withdraw' record + if (empty($tabtp[$obj->rowid]) && !empty($tabmoreinfo[$obj->rowid]['withdraw'])) // If we dont find 'company' link because it is an old 'withdraw' record + { @@ -570,7 +430,7 @@ - if (is_array($arrayofamounts)) { - foreach ($arrayofamounts as $invoiceid => $amount) { - $tmpinvoice->fetch($invoiceid); - $tmpinvoice->fetch_thirdparty(); - if ($tmpinvoice->thirdparty->code_compta) { - $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta] += $amount; - } + foreach ($arrayofamounts as $invoiceid => $amount) + { + $tmpinvoice->fetch($invoiceid); + $tmpinvoice->fetch_thirdparty(); + if ($tmpinvoice->thirdparty->code_compta) + { + $tabtp[$obj->rowid][$tmpinvoice->thirdparty->code_compta] += $amount; @@ -583,4 +443,2 @@ - // If no links were found to know the amount on thirdparty/user, we init it to account 'NotDefined'. - if (empty($tabtp[$obj->rowid])) { - $tabtp[$obj->rowid]['NotDefined'] = $tabbq[$obj->rowid][$compta_bank]; - } + // If no links were found to know the amount on thirdparty, we init it to account 'NotDefined'. + if (empty($tabtp[$obj->rowid])) $tabtp[$obj->rowid]['NotDefined'] = $tabbq[$obj->rowid][$compta_bank]; @@ -607 +465 @@ - // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $amounttouse; + // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount; @@ -616,5 +474,5 @@ -//var_dump($tabpay); -//var_dump($tabcompany); -//var_dump($tabbq); -//var_dump($tabtp); -//var_dump($tabtype); +/*var_dump($tabpay); +var_dump($tabcompany); +var_dump($tabbq); +var_dump($tabtp); +var_dump($tabtype);*/ @@ -626,12 +483,0 @@ - $accountingaccountcustomer = new AccountingAccount($db); - $accountingaccountcustomer->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, true); - - $accountingaccountsupplier = new AccountingAccount($db); - $accountingaccountsupplier->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, true); - - $accountingaccountpayment = new AccountingAccount($db); - $accountingaccountpayment->fetch(null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT, true); - - $accountingaccountsuspense = new AccountingAccount($db); - $accountingaccountsuspense->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE, true); - @@ -639,2 +485,3 @@ - foreach ($tabpay as $key => $val) { // $key is rowid into llx_bank - $date = dol_print_date($val["date"], 'day'); + foreach ($tabpay as $key => $val) // $key is rowid into llx_bank + { + $date = dol_print_date($db->jdate($val["date"]), 'day'); @@ -652,3 +499,3 @@ - //var_dump($tabpay); - //var_dump($tabtp); - //var_dump($tabbq);exit; + /*var_dump($tabpay); + var_dump($tabtp); + var_dump($tabbq);exit;*/ @@ -657 +504,2 @@ - if (!$errorforline && is_array($tabbq[$key])) { + if (!$errorforline && is_array($tabbq[$key])) + { @@ -659,5 +507,4 @@ - foreach ($tabbq[$key] as $k => $mt) { - if ($mt) { - $accountingaccount->fetch(null, $k, true); // $k is accounting bank account. TODO We should use a cache here to avoid this fetch - $account_label = $accountingaccount->label; - + foreach ($tabbq[$key] as $k => $mt) + { + if ($mt) + { @@ -665,3 +512 @@ - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib'])." - "; - } + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib'])." - "; @@ -669,3 +514 @@ - if (!empty($val['soclib'])) { - $reflabel .= " - ".dol_string_nohtmltag($val['soclib']); - } + if (!empty($val['soclib'])) $reflabel .= " - ".dol_string_nohtmltag($val['soclib']); @@ -679 +521,0 @@ - @@ -681 +523,3 @@ - $bookkeeping->label_compte = $account_label; + + $accountingaccount->fetch(null, $k, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -689 +533 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -703 +547,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -707 +552,3 @@ - } else { + } + else + { @@ -718,2 +565,4 @@ - if (!$errorforline) { - if (is_array($tabtp[$key])) { + if (!$errorforline) + { + if (is_array($tabtp[$key])) + { @@ -722,3 +571,2 @@ - if ($mt) { - $lettering = false; - + if ($mt) + { @@ -726,2 +574,4 @@ - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : ""); + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : ""); + if ($tabtype[$key] == 'banktransfert') + { + $reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer); @@ -729,3 +579,2 @@ - if ($tabtype[$key] == 'banktransfert') { - $reflabel .= dol_string_nohtmltag($langs->transnoentitiesnoconv('TransitionalAccount').' '.$account_transfer); - } else { + else + { @@ -741 +589,0 @@ - @@ -748 +596 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -753 +600,0 @@ - $lettering = true; @@ -757 +604,3 @@ - $bookkeeping->label_compte = $accountingaccountcustomer->label; + + $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -759 +607,0 @@ - $lettering = true; @@ -763 +611,3 @@ - $bookkeeping->label_compte = $accountingaccountsupplier->label; + + $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -768 +618,3 @@ - $bookkeeping->label_compte = $accountingaccountpayment->label; + + $accountingaccount->fetch(null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -773 +625,3 @@ - $bookkeeping->label_compte = $accountingaccountpayment->label; + + $accountingaccount->fetch(null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -777 +630,0 @@ - $accountingaccount->fetch(null, $k, true); // TODO Use a cache @@ -778,0 +632,2 @@ + + $accountingaccount->fetch(null, $k, true); @@ -783 +637,0 @@ - $accountingaccount->fetch(null, $k, true); // TODO Use a cache @@ -784,0 +639,2 @@ + + $accountingaccount->fetch(null, $k, true); @@ -789 +644,0 @@ - $accountingaccount->fetch(null, $k, true); // TODO Use a cache @@ -790,0 +646,2 @@ + + $accountingaccount->fetch(null, $k, true); @@ -795 +651,0 @@ - $accountingaccount->fetch(null, $k, true); // TODO Use a cache @@ -796,0 +653,2 @@ + + $accountingaccount->fetch(null, $k, true); @@ -801 +658,0 @@ - $accountingaccount->fetch(null, $k, true); // TODO Use a cache @@ -802,0 +660,2 @@ + + $accountingaccount->fetch(null, $k, true); @@ -806,2 +665 @@ - $bookkeeping->subledger_label = $tabcompany[$key]['name']; - $accountingaccount->fetch(null, $tabpay[$key]["account_various"], true); // TODO Use a cache + $bookkeeping->subledger_label = $tabcompany[$key]['name']; @@ -808,0 +667,2 @@ + + $accountingaccount->fetch(null, $bookkeeping->numero_compte, true); @@ -813 +672,0 @@ - $accountingaccount->fetch(null, $k, true); // TODO Use a cache @@ -814,0 +674,2 @@ + + $accountingaccount->fetch(null, $k, true); @@ -817 +678,2 @@ - if ($tabtype[$key] == 'unknown') { // Unknown transaction, we will use a waiting account for thirdparty. + if ($tabtype[$key] == 'unknown') // Unknown transaction, we will use a waiting account for thirdparty. + { @@ -822 +684,3 @@ - $bookkeeping->label_compte = $accountingaccountsuspense->label; + + $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -833 +697,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -837 +702,3 @@ - } else { + } + else + { @@ -842,6 +708,0 @@ - } else { - if ($lettering && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) { - require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; - $lettering_static = new Lettering($db); - $nb_lettering = $lettering_static->bookkeepingLetteringAll(array($bookkeeping->id)); - } @@ -851 +712,2 @@ - } else { // If thirdparty unknown, output the waiting account + } + else { // If thirdparty unknown, output the waiting account @@ -853 +715,2 @@ - if ($mt) { + if ($mt) + { @@ -855,3 +718 @@ - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib'])." - "; - } + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib'])." - "; @@ -871 +732 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -884 +745,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -888 +750,3 @@ - } else { + } + else + { @@ -899 +763,2 @@ - if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) { + if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) + { @@ -902,4 +767,5 @@ - setEventMessages('We tried to insert a non balanced transaction in book for '.$ref.'. Canceled. Surely a bug.', null, 'errors'); - } - - if (!$errorforline) { + setEventMessages('Try to insert a non balanced transaction in book for '.$ref.'. Canceled. Surely a bug.', null, 'errors'); + } + + if (!$errorforline) + { @@ -907 +773,3 @@ - } else { + } + else + { @@ -912 +780,2 @@ - if ($error >= $MAXNBERRORS) { + if ($error >= $MAXNBERRORS) + { @@ -921 +790,3 @@ - } elseif (count($tabpay) == $error) { + } + elseif (count($tabpay) == $error) + { @@ -923 +794,3 @@ - } else { + } + else + { @@ -930 +803,2 @@ - if (count($tabpay) != $error) { + if (count($tabpay) != $error) + { @@ -948 +822 @@ - $sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV'); + $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; @@ -962,2 +836,2 @@ - print '"'.$langs->transnoentitiesnoconv("AccountingDebit").'"'.$sep; - print '"'.$langs->transnoentitiesnoconv("AccountingCredit").'"'.$sep; + print '"'.$langs->transnoentitiesnoconv("Debit").'"'.$sep; + print '"'.$langs->transnoentitiesnoconv("Credit").'"'.$sep; @@ -968,2 +842,3 @@ - foreach ($tabpay as $key => $val) { - $date = dol_print_date($val["date"], 'day'); + foreach ($tabpay as $key => $val) + { + $date = dol_print_date($db->jdate($val["date"]), 'day'); @@ -975 +850,2 @@ - if ($mt) { + if ($mt) + { @@ -977,3 +853 @@ - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib'])." - "; - } + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib'])." - "; @@ -981,3 +855 @@ - if (!empty($val['soclib'])) { - $reflabel .= " - ".dol_string_nohtmltag($val['soclib']); - } + if (!empty($val['soclib'])) $reflabel .= " - ".dol_string_nohtmltag($val['soclib']); @@ -989 +861 @@ - print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; + print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; @@ -1003 +875,2 @@ - if ($mt) { + if ($mt) + { @@ -1005,4 +878,3 @@ - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : ""); - } - if ($tabtype[$key] == 'banktransfert') { + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib']).($val['soclib'] ? " - " : ""); + if ($tabtype[$key] == 'banktransfert') + { @@ -1010 +882,3 @@ - } else { + } + else + { @@ -1017 +891 @@ - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; @@ -1019 +893 @@ - print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER').'"'.$sep; + print '"'.$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER.'"'.$sep; @@ -1021 +895 @@ - print '"'.getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER').'"'.$sep; + print '"'.$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER.'"'.$sep; @@ -1023 +897 @@ - print '"'.getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').'"'.$sep; + print '"'.$conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT.'"'.$sep; @@ -1025 +899 @@ - print '"'.getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT').'"'.$sep; + print '"'.$conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT.'"'.$sep; @@ -1027 +901 @@ - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; @@ -1040 +914,2 @@ - if ($mt) { + if ($mt) + { @@ -1042,3 +917 @@ - if (!empty($val['lib'])) { - $reflabel .= dol_string_nohtmltag($val['lib'])." - "; - } + if (!empty($val['lib'])) $reflabel .= dol_string_nohtmltag($val['lib'])." - "; @@ -1050,3 +923,3 @@ - print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE')).'"'.$sep; - print '"'.length_accounta(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE')).'"'.$sep; - print $sep; + print '"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).'"'.$sep; + print '"'.length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE).'"'.$sep; + print "".$sep; @@ -1079 +952 @@ - $salarystatic = new Salary($db); + $salarystatic = new PaymentSalary($db); @@ -1082,5 +955,3 @@ - $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1); - - llxHeader('', dol_string_nohtmltag($title)); - - $nom = $title; + llxHeader('', $langs->trans("FinanceJournal")); + + $nom = $langs->trans("FinanceJournal").' | '.$accountingjournalstatic->getNomUrl(0, 1, 1, '', 1); @@ -1089,8 +960,5 @@ - $description = $langs->trans("DescJournalOnlyBindedVisible").'
'; - - $listofchoices = array( - 'notyet'=>$langs->trans("NotYetInGeneralLedger"), - 'already'=>$langs->trans("AlreadyInGeneralLedger") - ); - $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0); - $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); + $description .= $langs->trans("DescJournalOnlyBindedVisible").'
'; + + $listofchoices = array('notyet'=>$langs->trans("NotYetInGeneralLedger"), 'already'=>$langs->trans("AlreadyInGeneralLedger")); + $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0); + $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); @@ -1099,2 +966,0 @@ - $periodlink = ''; - $exportlink = ''; @@ -1104,23 +970,3 @@ - $desc = ''; - - if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') != 'blockedonclosed') { - // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed) - // Fiscal period test - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE entity = ".((int) $conf->entity); - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - if ($obj->nb == 0) { - print '
'.img_warning().' '.$langs->trans("TheFiscalPeriodIsNotDefined"); - $desc = ' : '.$langs->trans("AccountancyAreaDescFiscalPeriod", 4, '{link}'); - $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("FiscalPeriod").'', $desc); - print $desc; - print '
'; - } - } else { - dol_print_error($db); - } - } - - // Bank test - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."bank_account WHERE entity = ".((int) $conf->entity)." AND fk_accountancy_journal IS NULL AND clos=0"; + + // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed) + $sql = 'SELECT COUNT(rowid) as nb FROM '.MAIN_DB_PREFIX.'bank_account WHERE entity = '.$conf->entity.' AND fk_accountancy_journal IS NULL AND clos=0'; @@ -1128 +974,2 @@ - if ($resql) { + if ($resql) + { @@ -1130,10 +977,7 @@ - if ($obj->nb > 0) { - print '
'.img_warning().' '.$langs->trans("TheJournalCodeIsNotDefinedOnSomeBankAccount"); - $desc = ' : '.$langs->trans("AccountancyAreaDescBank", 6, '{link}'); - $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("BankAccounts").'', $desc); - print $desc; - print '
'; - } - } else { - dol_print_error($db); - } + if ($obj->nb > 0) + { + print '
'.img_warning().' '.$langs->trans("TheJournalCodeIsNotDefinedOnSomeBankAccount"); + print ' : '.$langs->trans("AccountancyAreaDescBank", 9, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("BankAccounts").''); + } + } + else dol_print_error($db); @@ -1143,26 +987,19 @@ - if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == '-1' - || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == '-1' - || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == "" || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == '-1') { - print($desc ? '' : '
').'
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); - $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}'); - $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'', $desc); - print $desc; - print '
'; - } - - - print '
'; - - if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') { - print ''; - } - - if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER') == '-1' - || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == "" || getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER') == '-1') { - print ''; - } else { - if ($in_bookkeeping == 'notyet') { - print ''; - } else { - print ''.$langs->trans("WriteBookKeeping").''; - } + if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1' + || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == "") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1' + || empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') { + print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + } + + + print '
'; + + if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') print ''; + + if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1' + || ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == "") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1') { + print ''; + } + else { + if ($in_bookkeeping == 'notyet') print ''; + else print ''.$langs->trans("WriteBookKeeping").''; @@ -1197,2 +1034,2 @@ - print ''; - print ''; + print "
"; + print ""; @@ -1205,2 +1042,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -1211,2 +1048,3 @@ - foreach ($tabpay as $key => $val) { // $key is rowid in llx_bank - $date = dol_print_date($val["date"], 'day'); + foreach ($tabpay as $key => $val) // $key is rowid in llx_bank + { + $date = dol_print_date($db->jdate($val["date"]), 'day'); @@ -1217,2 +1055,4 @@ - foreach ($tabbq[$key] as $k => $mt) { - if ($mt) { + foreach ($tabbq[$key] as $k => $mt) + { + if ($mt) + { @@ -1220,3 +1060 @@ - if (!empty($val['lib'])) { - $reflabel .= $val['lib']." - "; - } + if (!empty($val['lib'])) $reflabel .= $val['lib']." - "; @@ -1224,3 +1062 @@ - if (!empty($val['soclib'])) { - $reflabel .= " - ".$val['soclib']; - } + if (!empty($val['soclib'])) $reflabel .= " - ".$val['soclib']; @@ -1231,2 +1066,0 @@ - - // Date @@ -1234,4 +1068 @@ - - // Ref - print ""; - + print ""; @@ -1238,0 +1070 @@ + print ""; - print '"; + print '"; + print '"; @@ -1266,2 +1093,0 @@ - - $i++; @@ -1274 +1100,2 @@ - if ($mt) { + if ($mt) + { @@ -1276,4 +1103,3 @@ - if (!empty($val['lib'])) { - $reflabel .= $val['lib'].($val['soclib'] ? " - " : ""); - } - if ($tabtype[$key] == 'banktransfert') { + if (!empty($val['lib'])) $reflabel .= $val['lib'].($val['soclib'] ? " - " : ""); + if ($tabtype[$key] == 'banktransfert') + { @@ -1281 +1107,3 @@ - } else { + } + else + { @@ -1287,2 +1114,0 @@ - - // Date @@ -1290,4 +1116 @@ - - // Ref - print ""; - + print ""; @@ -1294,0 +1118 @@ + print ""; - - print '"; - + print '"; + print '"; @@ -1393,2 +1194,0 @@ - - $i++; @@ -1399 +1199,2 @@ - if ($mt) { + if ($mt) + { @@ -1401,3 +1202 @@ - if (!empty($val['lib'])) { - $reflabel .= $val['lib']." - "; - } + if (!empty($val['lib'])) $reflabel .= $val['lib']." - "; @@ -1416,2 +1215 @@ - else */ - print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE); + else */ print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE); @@ -1428 +1226 @@ - print ""; + print ""; @@ -1430,2 +1228,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -1433,2 +1230,0 @@ - - $i++; @@ -1438,5 +1233,0 @@ - } - - if (!$i) { - $colspan = 8; - print ''; @@ -1495,14 +1286,5 @@ - if ($typerecord == 'payment') { - if (getDolGlobalInt('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { - $sqlmid = "SELECT payfac.fk_facture as id, ".$db->ifsql('f1.rowid IS NULL', 'f.ref', 'f1.ref')." as ref"; - $sqlmid .= " FROM ".$db->prefix()."paiement_facture as payfac"; - $sqlmid .= " LEFT JOIN ".$db->prefix()."facture as f ON f.rowid = payfac.fk_facture"; - $sqlmid .= " LEFT JOIN ".$db->prefix()."societe_remise_except as sre ON sre.fk_facture_source = payfac.fk_facture"; - $sqlmid .= " LEFT JOIN ".$db->prefix()."facture as f1 ON f1.rowid = sre.fk_facture"; - $sqlmid .= " WHERE payfac.fk_paiement=".((int) $val['paymentid']); - } else { - $sqlmid = "SELECT payfac.fk_facture as id, f.ref as ref"; - $sqlmid .= " FROM ".$db->prefix()."paiement_facture as payfac"; - $sqlmid .= " INNER JOIN ".$db->prefix()."facture as f ON f.rowid = payfac.fk_facture"; - $sqlmid .= " WHERE payfac.fk_paiement=".((int) $val['paymentid']); - } + if ($typerecord == 'payment') + { + $sqlmid = 'SELECT payfac.fk_facture as id, f.ref as ref'; + $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiement_facture as payfac, ".MAIN_DB_PREFIX."facture as f"; + $sqlmid .= " WHERE payfac.fk_facture = f.rowid AND payfac.fk_paiement=".$val["paymentid"]; @@ -1510 +1292,3 @@ - } elseif ($typerecord == 'payment_supplier') { + } + elseif ($typerecord == 'payment_supplier') + { @@ -1513 +1297 @@ - $sqlmid .= " WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".((int) $val["paymentsupplierid"]); + $sqlmid .= " WHERE payfac.fk_facturefourn = f.rowid AND payfac.fk_paiementfourn=".$val["paymentsupplierid"]; @@ -1515 +1299,3 @@ - } elseif ($typerecord == 'payment_expensereport') { + } + elseif ($typerecord == 'payment_expensereport') + { @@ -1518 +1304 @@ - $sqlmid .= " WHERE pe.rowid=".((int) $val["paymentexpensereport"])." AND pe.fk_expensereport = e.rowid"; + $sqlmid .= " WHERE pe.rowid=".$val["paymentexpensereport"]." AND pe.fk_expensereport = e.rowid"; @@ -1520 +1306,3 @@ - } elseif ($typerecord == 'payment_salary') { + } + elseif ($typerecord == 'payment_salary') + { @@ -1523 +1311 @@ - $sqlmid .= " WHERE s.rowid=".((int) $val["paymentsalid"]); + $sqlmid .= " WHERE s.rowid=".$val["paymentsalid"]; @@ -1525 +1313,3 @@ - } elseif ($typerecord == 'sc') { + } + elseif ($typerecord == 'sc') + { @@ -1528 +1318 @@ - $sqlmid .= " WHERE sc.rowid=".((int) $val["paymentscid"]); + $sqlmid .= " WHERE sc.rowid=".$val["paymentscid"]; @@ -1530 +1320,3 @@ - } elseif ($typerecord == 'payment_vat') { + } + elseif ($typerecord == 'payment_vat') + { @@ -1533 +1325 @@ - $sqlmid .= " WHERE v.rowid=".((int) $val["paymentvatid"]); + $sqlmid .= " WHERE v.rowid=".$val["paymentvatid"]; @@ -1535 +1327,3 @@ - } elseif ($typerecord == 'payment_donation') { + } + elseif ($typerecord == 'payment_donation') + { @@ -1538 +1332 @@ - $sqlmid .= " WHERE payd.fk_donation=".((int) $val["paymentdonationid"]); + $sqlmid .= " WHERE payd.fk_donation=".$val["paymentdonationid"]; @@ -1540 +1334,3 @@ - } elseif ($typerecord == 'payment_loan') { + } + elseif ($typerecord == 'payment_loan') + { @@ -1543 +1339 @@ - $sqlmid .= " WHERE l.rowid=".((int) $val["paymentloanid"]); + $sqlmid .= " WHERE l.rowid=".$val["paymentloanid"]; @@ -1545 +1341,3 @@ - } elseif ($typerecord == 'payment_various') { + } + elseif ($typerecord == 'payment_various') + { @@ -1548 +1346 @@ - $sqlmid .= " WHERE v.rowid=".((int) $val["paymentvariousid"]); + $sqlmid .= " WHERE v.rowid=".$val["paymentvariousid"]; @@ -1552 +1350,2 @@ - if (empty($sqlmid)) { + if (empty($sqlmid)) + { @@ -1556 +1355,2 @@ - if ($sqlmid) { + if ($sqlmid) + { @@ -1559,2 +1359,4 @@ - if ($resultmid) { - while ($objmid = $db->fetch_object($resultmid)) { + if ($resultmid) + { + while ($objmid = $db->fetch_object($resultmid)) + { @@ -1563,3 +1365,2 @@ - } else { - dol_print_error($db); - } + } + else dol_print_error($db); --- /tmp/dsg/dolibarr/htdocs/accountancy/journal/github_19.0.3_expensereportsjournal.php +++ /tmp/dsg/dolibarr/htdocs/accountancy/journal/client_expensereportsjournal.php @@ -2,9 +2,9 @@ -/* Copyright (C) 2007-2010 Laurent Destailleur - * Copyright (C) 2007-2010 Jean Heimburger - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2013-2024 Alexandre Spangaro - * Copyright (C) 2013-2016 Olivier Geffroy - * Copyright (C) 2013-2016 Florian Henry - * Copyright (C) 2018 Frédéric France - * Copyright (C) 2018 Eric Seigne +/* Copyright (C) 2007-2010 Laurent Destailleur + * Copyright (C) 2007-2010 Jean Heimburger + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2013-2018 Alexandre Spangaro + * Copyright (C) 2013-2016 Olivier Geffroy + * Copyright (C) 2013-2016 Florian Henry + * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018 Eric Seigne @@ -54,3 +54 @@ -if ($in_bookkeeping == '') { - $in_bookkeeping = 'notyet'; -} +if ($in_bookkeeping == '') $in_bookkeeping = 'notyet'; @@ -60,3 +57,0 @@ -$hookmanager->initHooks(array('expensereportsjournal')); -$parameters = array(); - @@ -64 +59 @@ -if (!isModEnabled('accounting')) { +if ($user->socid > 0) @@ -66,11 +60,0 @@ -} -if ($user->socid > 0) { - accessforbidden(); -} -if (!$user->hasRight('accounting', 'mouvements', 'lire')) { - accessforbidden(); -} - -$error = 0; -$errorforinvoice = array(); - @@ -81 +64,0 @@ - @@ -89,0 +73,8 @@ +$year_current = strftime("%Y", dol_now()); +$pastmonth = strftime("%m", dol_now()) - 1; +$pastmonthyear = $year_current; +if ($pastmonth == 0) { + $pastmonth = 12; + $pastmonthyear--; +} + @@ -93,16 +84,2 @@ -if (empty($date_startmonth)) { - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_start = $dates['date_start']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} -if (empty($date_endmonth)) { - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_end = $dates['date_end']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} - -if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) { // We define date_start and date_end, only if we did not submit the form +if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) // We define date_start and date_end, only if we did not submit the form +{ @@ -117,3 +93,0 @@ -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; @@ -125,3 +98,0 @@ -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; @@ -131 +102 @@ -if ($date_start && $date_end) { +if ($date_start && $date_end) @@ -133,5 +103,0 @@ -} -// Define begin binding date -if (getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) { - $sql .= " AND er.date_debut >= '".$db->idate(getDolGlobalString('ACCOUNTING_DATE_START_BINDING'))."'"; -} @@ -139,9 +105,8 @@ -if ($in_bookkeeping == 'already') { - $sql .= " AND er.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')"; -} -if ($in_bookkeeping == 'notyet') { - $sql .= " AND er.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')"; -} -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; +if ($in_bookkeeping == 'already') +{ + $sql .= " AND er.rowid IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')"; +} +if ($in_bookkeeping == 'notyet') +{ + $sql .= " AND er.rowid NOT IN (SELECT fk_doc FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='expense_report')"; +} @@ -165,2 +130,2 @@ - $account_salary = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', 'NotDefined'); - $account_vat = getDolGlobalString('ACCOUNTING_VAT_BUY_ACCOUNT', 'NotDefined'); + $account_salary = (!empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT)) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : 'NotDefined'; + $account_vat = (!empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : 'NotDefined'; @@ -178,2 +143,2 @@ - $compta_localtax1 = (!empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $account_vat); - $compta_localtax2 = (!empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $account_vat); + $compta_localtax1 = (!empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $cpttva); + $compta_localtax2 = (!empty($vatdata['accountancy_code_buy']) ? $vatdata['accountancy_code_buy'] : $cpttva); @@ -182 +147,2 @@ - if (price2num($obj->tva_tx) || !empty($obj->vat_src_code)) { + if (price2num($obj->tva_tx) || !empty($obj->vat_src_code)) + { @@ -192,15 +158,5 @@ - if (!isset($tabttc[$obj->rowid][$compta_user])) { - $tabttc[$obj->rowid][$compta_user] = 0; - } - if (!isset($tabht[$obj->rowid][$compta_fees])) { - $tabht[$obj->rowid][$compta_fees] = 0; - } - if (!isset($tabtva[$obj->rowid][$compta_tva])) { - $tabtva[$obj->rowid][$compta_tva] = 0; - } - if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) { - $tablocaltax1[$obj->rowid][$compta_localtax1] = 0; - } - if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) { - $tablocaltax2[$obj->rowid][$compta_localtax2] = 0; - } + if (!isset($tabttc[$obj->rowid][$compta_user])) $tabttc[$obj->rowid][$compta_user] = 0; + if (!isset($tabht[$obj->rowid][$compta_fees])) $tabht[$obj->rowid][$compta_fees] = 0; + if (!isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0; + if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) $tablocaltax1[$obj->rowid][$compta_localtax1] = 0; + if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) $tablocaltax2[$obj->rowid][$compta_localtax2] = 0; @@ -225,19 +180,0 @@ -// Load all unbound lines -$sql = "SELECT fk_expensereport, COUNT(erd.rowid) as nb"; -$sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd"; -$sql .= " WHERE erd.fk_code_ventilation <= 0"; -$sql .= " AND erd.total_ttc <> 0"; -$sql .= " AND fk_expensereport IN (".$db->sanitize(join(",", array_keys($taber))).")"; -$sql .= " GROUP BY fk_expensereport"; -$resql = $db->query($sql); - -$num = $db->num_rows($resql); -$i = 0; -while ($i < $num) { - $obj = $db->fetch_object($resql); - if ($obj->nb > 0) { - $errorforinvoice[$obj->fk_expensereport] = 'somelinesarenotbound'; - } - $i++; -} - @@ -245 +182 @@ -if ($action == 'writebookkeeping' && !$error) { +if ($action == 'writebookkeeping') { @@ -249,4 +186,2 @@ - $accountingaccountexpense = new AccountingAccount($db); - $accountingaccountexpense->fetch(null, getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'), true); - - foreach ($taber as $key => $val) { // Loop on each expense report + foreach ($taber as $key => $val) // Loop on each expense report + { @@ -260,7 +194,0 @@ - // Error if some lines are not binded/ready to be journalized - if (!empty($errorforinvoice[$key]) && $errorforinvoice[$key] == 'somelinesarenotbound') { - $error++; - $errorforline++; - setEventMessages($langs->trans('ErrorInvoiceContainsLinesNotYetBounded', $val['ref']), null, 'errors'); - } - @@ -268 +196,2 @@ - if (!$errorforline) { + if (!$errorforline) + { @@ -278 +206,0 @@ - @@ -281,3 +209,4 @@ - - $bookkeeping->numero_compte = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'); - $bookkeeping->label_compte = $accountingaccountexpense->label; + $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + + $accountingaccount->fetch(null, $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -291 +220 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -300 +229,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -303 +232,0 @@ - $errorforinvoice[$key] = 'alreadyjournalized'; @@ -305 +234,3 @@ - } else { + } + else + { @@ -308 +238,0 @@ - $errorforinvoice[$key] = 'other'; @@ -317 +247,2 @@ - if (!$errorforline) { + if (!$errorforline) + { @@ -329 +259,0 @@ - @@ -332 +261,0 @@ - @@ -335 +263,0 @@ - @@ -340 +268 @@ - $bookkeeping->credit = ($mt <= 0) ? -$mt : 0; + $bookkeeping->credit = ($mt <= 0) ? $mt : 0; @@ -342 +270 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -351 +279,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -354 +282,0 @@ - $errorforinvoice[$key] = 'alreadyjournalized'; @@ -356 +284,3 @@ - } else { + } + else + { @@ -359 +288,0 @@ - $errorforinvoice[$key] = 'other'; @@ -369 +298,2 @@ - if (!$errorforline) { + if (!$errorforline) + { @@ -371 +301,2 @@ - foreach ($listoftax as $numtax) { + foreach ($listoftax as $numtax) + { @@ -373,6 +304,2 @@ - if ($numtax == 1) { - $arrayofvat = $tablocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tablocaltax2; - } + if ($numtax == 1) $arrayofvat = $tablocaltax1; + if ($numtax == 2) $arrayofvat = $tablocaltax2; @@ -382,3 +308,0 @@ - $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label - $account_label = $accountingaccount->label; - @@ -393 +316,0 @@ - @@ -396 +318,0 @@ - @@ -398 +320,3 @@ - $bookkeeping->label_compte = $account_label; + + $accountingaccount->fetch($k, null, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -404 +328 @@ - $bookkeeping->credit = ($mt <= 0) ? -$mt : 0; + $bookkeeping->credit = ($mt <= 0) ? $mt : 0; @@ -406 +330 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -415 +339,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -418 +342,0 @@ - $errorforinvoice[$key] = 'alreadyjournalized'; @@ -420 +344,3 @@ - } else { + } + else + { @@ -423 +348,0 @@ - $errorforinvoice[$key] = 'other'; @@ -432,2 +357,3 @@ - // Protection against a bug on lines before - if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) { + // Protection against a bug on line before + if (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT')) + { @@ -436,5 +362,5 @@ - $errorforinvoice[$key] = 'amountsnotbalanced'; - setEventMessages('We tried to insert a non balanced transaction in book for '.$val["ref"].'. Canceled. Surely a bug.', null, 'errors'); - } - - if (!$errorforline) { + setEventMessages('Try to insert a non balanced transaction in book for '.$val["ref"].'. Canceled. Surely a bug.', null, 'errors'); + } + + if (!$errorforline) + { @@ -442 +368,3 @@ - } else { + } + else + { @@ -445,3 +373,4 @@ - if ($error >= 10) { - setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); - break; // Break in the foreach + if ($error >= 10) + { + setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); + break; // Break in the foreach @@ -456 +385,3 @@ - } elseif (count($tabpay) == $error) { + } + elseif (count($tabpay) == $error) + { @@ -458 +389,3 @@ - } else { + } + else + { @@ -465 +398,2 @@ - if (count($tabpay) != $error) { + if (count($tabpay) != $error) + { @@ -490 +424 @@ -if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 ! +if ($action == 'exportcsv') { // ISO and not UTF8 ! @@ -502,2 +436,2 @@ - print '"'.$langs->transnoentitiesnoconv("AccountingDebit").'"'.$sep; - print '"'.$langs->transnoentitiesnoconv("AccountingCredit").'"'.$sep; + print '"'.$langs->transnoentitiesnoconv("Debit").'"'.$sep; + print '"'.$langs->transnoentitiesnoconv("Credit").'"'.$sep; @@ -507,43 +441,42 @@ - $date = dol_print_date($val["date"], 'day'); - - $userstatic->id = $tabuser[$key]['id']; - $userstatic->name = $tabuser[$key]['name']; - - // Fees - foreach ($tabht[$key] as $k => $mt) { - $accountingaccount = new AccountingAccount($db); - $accountingaccount->fetch(null, $k, true); - if ($mt) { - print '"'.$date.'"'.$sep; - print '"'.$val["ref"].'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '"'.dol_trunc($accountingaccount->label, 32).'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'; - print "\n"; - } - } - - // VAT - foreach ($tabtva[$key] as $k => $mt) { - if ($mt) { - print '"'.$date.'"'.$sep; - print '"'.$val["ref"].'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '"'.dol_trunc($langs->trans("VAT")).'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'; - print "\n"; - } - } - - // Third party - foreach ($tabttc[$key] as $k => $mt) { - print '"'.$date.'"'.$sep; - print '"'.$val["ref"].'"'.$sep; - print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; - print '"'.dol_trunc($userstatic->name).'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'; - } - print "\n"; + $date = dol_print_date($val["date"], 'day'); + + $userstatic->id = $tabuser[$key]['id']; + $userstatic->name = $tabuser[$key]['name']; + + // Fees + foreach ($tabht[$key] as $k => $mt) { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(null, $k, true); + if ($mt) { + print '"'.$date.'"'.$sep; + print '"'.$val["ref"].'"'.$sep; + print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.dol_trunc($accountingaccount->label, 32).'"'.$sep; + print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; + print '"'.($mt < 0 ? price(-$mt) : '').'"'; + print "\n"; + } + } + // VAT + foreach ($tabtva[$key] as $k => $mt) { + if ($mt) { + print '"'.$date.'"'.$sep; + print '"'.$val["ref"].'"'.$sep; + print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.dol_trunc($langs->trans("VAT")).'"'.$sep; + print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; + print '"'.($mt < 0 ? price(-$mt) : '').'"'; + print "\n"; + } + } + + // Third party + foreach ($tabttc[$key] as $k => $mt) { + print '"'.$date.'"'.$sep; + print '"'.$val["ref"].'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; + print '"'.dol_trunc($userstatic->name).'"'.$sep; + print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; + print '"'.($mt >= 0 ? price($mt) : '').'"'; + } + print "\n"; @@ -554,5 +487,3 @@ - $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1); - - llxHeader('', dol_string_nohtmltag($title)); - - $nom = $title; + llxHeader('', $langs->trans("ExpenseReportsJournal")); + + $nom = $langs->trans("ExpenseReportsJournal").' | '.$accountingjournalstatic->getNomUrl(0, 1, 1, '', 1); @@ -563 +494 @@ - $description = $langs->trans("DescJournalOnlyBindedVisible").'
'; + $description .= $langs->trans("DescJournalOnlyBindedVisible").'
'; @@ -566,2 +497,2 @@ - $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0); - $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); + $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0); + $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); @@ -573,19 +503,0 @@ - if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') != 'blockedonclosed') { - // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed) - // Fiscal period test - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE entity = ".((int) $conf->entity); - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - if ($obj->nb == 0) { - print '
'.img_warning().' '.$langs->trans("TheFiscalPeriodIsNotDefined"); - $desc = ' : '.$langs->trans("AccountancyAreaDescFiscalPeriod", 4, '{link}'); - $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("FiscalPeriod").'', $desc); - print $desc; - print '
'; - } - } else { - dol_print_error($db); - } - } - @@ -593,13 +505,8 @@ - if (!getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == '-1') { - print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); - $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}'); - $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'', $desc); - print $desc; - print '
'; - } - print '
'; - - if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') { - print ''; - } - if (!getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') || getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT') == '-1') { + if (empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') { + print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + } + print '
'; + + if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') print ''; + if (empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT) || $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT == '-1') { @@ -607,6 +514,4 @@ - } else { - if ($in_bookkeeping == 'notyet') { - print ''; - } else { - print ''.$langs->trans("WriteBookKeeping").''; - } + } + else { + if ($in_bookkeeping == 'notyet') print ''; + else print ''.$langs->trans("WriteBookKeeping").''; @@ -646,2 +551,2 @@ - print '
"; - print '"; + print '"; + print '"; @@ -650 +555 @@ - $i = 0; + $r = ''; @@ -661,21 +565,0 @@ - - if ($errorforinvoice[$key] == 'somelinesarenotbound') { - print ''; - print ""; - print ""; - print ""; - // Account - print "'; - // Subledger account - print "'; - print ""; - print ''; - print ''; - print ""; - - $i++; - } @@ -698 +582,2 @@ - if (($accountoshow == "") || $accountoshow == 'NotDefined') { + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { @@ -700,2 +584,0 @@ - } else { - print $accountoshow; @@ -702,0 +586 @@ + else print $accountoshow; @@ -710,2 +594,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -713,2 +596,0 @@ - - $i++; @@ -729,2 +611,3 @@ - $accountoshow = length_accountg(getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT')); - if (($accountoshow == "") || $accountoshow == 'NotDefined') { + $accountoshow = length_accounta($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT); + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { @@ -732,3 +615,2 @@ - } else { - print $accountoshow; - } + } + else print $accountoshow; @@ -739 +621,2 @@ - if (($accountoshow == "") || $accountoshow == 'NotDefined') { + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { @@ -741,3 +624,2 @@ - } else { - print $accountoshow; - } + } + else print $accountoshow; @@ -746,2 +628,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -749,2 +630,0 @@ - - $i++; @@ -757,6 +637,2 @@ - if ($numtax == 1) { - $arrayofvat = $tablocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tablocaltax2; - } + if ($numtax == 1) $arrayofvat = $tablocaltax1; + if ($numtax == 2) $arrayofvat = $tablocaltax2; @@ -773 +649,2 @@ - if (($accountoshow == "") || $accountoshow == 'NotDefined') { + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { @@ -775,2 +651,0 @@ - } else { - print $accountoshow; @@ -777,0 +653 @@ + else print $accountoshow; @@ -784,2 +660,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -787,2 +662,0 @@ - - $i++; @@ -792,5 +665,0 @@ - } - - if (!$i) { - $colspan = 7; - print ''; --- /tmp/dsg/dolibarr/htdocs/accountancy/journal/github_19.0.3_purchasesjournal.php +++ /tmp/dsg/dolibarr/htdocs/accountancy/journal/client_purchasesjournal.php @@ -6 +6 @@ - * Copyright (C) 2013-2023 Alexandre Spangaro + * Copyright (C) 2013-2017 Alexandre Spangaro @@ -35 +34,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; @@ -55,3 +54 @@ -if ($in_bookkeeping == '') { - $in_bookkeeping = 'notyet'; -} +if ($in_bookkeeping == '') $in_bookkeeping = 'notyet'; @@ -59,0 +57,4 @@ + +// Security check +if ($user->socid > 0) + accessforbidden(); @@ -63,14 +63,0 @@ - -// Security check -if (!isModEnabled('accounting')) { - accessforbidden(); -} -if ($user->socid > 0) { - accessforbidden(); -} -if (!$user->hasRight('accounting', 'mouvements', 'lire')) { - accessforbidden(); -} - -$error = 0; - @@ -81 +67,0 @@ - @@ -91,0 +78,8 @@ +$year_current = strftime("%Y", dol_now()); +$pastmonth = strftime("%m", dol_now()) - 1; +$pastmonthyear = $year_current; +if ($pastmonth == 0) { + $pastmonth = 12; + $pastmonthyear--; +} + @@ -95,16 +89,2 @@ -if (empty($date_startmonth)) { - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_start = $dates['date_start']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} -if (empty($date_endmonth)) { - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_end = $dates['date_end']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} - -if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) { // We define date_start and date_end, only if we did not submit the form +if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) // We define date_start and date_end, only if we did not submit the form +{ @@ -115,21 +95,4 @@ -$sql = "SELECT f.rowid, f.ref as ref, f.type, f.datef as df, f.libelle as label, f.ref_supplier, f.date_lim_reglement as dlr, f.close_code, f.vat_reverse_charge,"; -$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.tva as total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.vat_src_code, fd.info_bits,"; -$sql .= " p.default_vat_code AS product_buy_default_vat_code, p.tva_tx as product_buy_vat, p.localtax1_tx as product_buy_localvat1, p.localtax2_tx as product_buy_localvat2,"; -$sql .= " co.code as country_code, co.label as country_label,"; -$sql .= " s.rowid as socid, s.nom as name, s.fournisseur, s.code_client, s.code_fournisseur, s.fk_pays,"; -if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { - $sql .= " spe.accountancy_code_customer as code_compta,"; - $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; -} else { - $sql .= " s.code_compta as code_compta,"; - $sql .= " s.code_compta_fournisseur,"; -} -if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { - $sql .= " ppe.accountancy_code_buy,"; -} else { - $sql .= " p.accountancy_code_buy,"; -} -$sql .= " aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; +$sql = "SELECT f.rowid, f.ref as ref, f.type, f.datef as df, f.libelle,f.ref_supplier, f.date_lim_reglement as dlf, f.close_code,"; +$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.tva as total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.vat_src_code,"; +$sql .= " s.rowid as socid, s.nom as name, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,"; +$sql .= " p.accountancy_code_buy , aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; @@ -138,3 +100,0 @@ -if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); -} @@ -144,7 +103,0 @@ -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays "; -if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); -} -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; @@ -154 +107 @@ -if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { +if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { @@ -159 +112 @@ -if ($date_start && $date_end) { +if ($date_start && $date_end) @@ -161,5 +113,0 @@ -} -// Define begin binding date -if (getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) { - $sql .= " AND f.datef >= '".$db->idate(getDolGlobalString('ACCOUNTING_DATE_START_BINDING'))."'"; -} @@ -167 +115,2 @@ -if ($in_bookkeeping == 'already') { +if ($in_bookkeeping == 'already') +{ @@ -170 +119,2 @@ -if ($in_bookkeeping == 'notyet') { +if ($in_bookkeeping == 'notyet') +{ @@ -173,3 +122,0 @@ -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; @@ -190,4 +136,0 @@ - $tabrctva = array(); - $tabrclocaltax1 = array(); - $tabrclocaltax2 = array(); - $vatdata_cache = array(); @@ -198,5 +141,2 @@ - $cptfour = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER', 'NotDefined'); - $cpttva = getDolGlobalString('ACCOUNTING_VAT_BUY_ACCOUNT', 'NotDefined'); - $rcctva = getDolGlobalString('ACCOUNTING_VAT_BUY_REVERSE_CHARGES_CREDIT', 'NotDefined'); - $rcdtva = getDolGlobalString('ACCOUNTING_VAT_BUY_REVERSE_CHARGES_DEBIT', 'NotDefined'); - $country_code_in_EEC = getCountriesInEEC(); // This make a database call but there is a cache done into $conf->cache['country_code_in_EEC'] + $cptfour = ($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER != "") ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : 'NotDefined'; + $cpttva = (!empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : 'NotDefined'; @@ -213,14 +153,7 @@ - if ($obj->product_type == 0) { - $compta_prod = getDolGlobalString('ACCOUNTING_PRODUCT_BUY_ACCOUNT', 'NotDefined'); - } else { - $compta_prod = getDolGlobalString('ACCOUNTING_SERVICE_BUY_ACCOUNT', 'NotDefined'); - } - } - - $tax_id = $obj->tva_tx . ($obj->vat_src_code ? ' (' . $obj->vat_src_code . ')' : ''); - if (array_key_exists($tax_id, $vatdata_cache)) { - $vatdata = $vatdata_cache[$tax_id]; - } else { - $vatdata = getTaxesFromId($tax_id, $mysoc, $mysoc, 0); - $vatdata_cache[$tax_id] = $vatdata; - } + if ($obj->product_type == 0) + $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : 'NotDefined'; + else + $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : 'NotDefined'; + } + + $vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), $mysoc, $mysoc, 0); @@ -230 +163 @@ - $compta_counterpart_tva_npr = getDolGlobalString('ACCOUNTING_COUNTERPART_VAT_NPR', 'NotDefined'); + $compta_counterpart_tva_npr = (!empty($conf->global->ACCOUNTING_COUNTERPART_VAT_NPR)) ? $conf->global->ACCOUNTING_COUNTERPART_VAT_NPR : 'NotDefined'; @@ -233 +166,2 @@ - if (price2num($obj->tva_tx) || !empty($obj->vat_src_code)) { + if (price2num($obj->tva_tx) || !empty($obj->vat_src_code)) + { @@ -237,2 +171,2 @@ - //$line = new SupplierInvoiceLine($db); - //$line->fetch($obj->fdid); + $line = new SupplierInvoiceLine($db); + $line->fetch($obj->fdid); @@ -251,62 +185,5 @@ - if (!isset($tabttc[$obj->rowid][$compta_soc])) { - $tabttc[$obj->rowid][$compta_soc] = 0; - } - if (!isset($tabht[$obj->rowid][$compta_prod])) { - $tabht[$obj->rowid][$compta_prod] = 0; - } - if (!isset($tabtva[$obj->rowid][$compta_tva])) { - $tabtva[$obj->rowid][$compta_tva] = 0; - } - if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) { - $tablocaltax1[$obj->rowid][$compta_localtax1] = 0; - } - if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) { - $tablocaltax2[$obj->rowid][$compta_localtax2] = 0; - } - - // VAT Reverse charge - if (($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) && $obj->vat_reverse_charge == 1 && in_array($obj->country_code, $country_code_in_EEC)) { - $rcvatdata = getTaxesFromId($obj->product_buy_vat . ($obj->product_buy_default_vat_code ? ' (' . $obj->product_buy_default_vat_code . ')' : ''), $mysoc, $mysoc, 0); - $rcc_compta_tva = (!empty($vatdata['accountancy_code_vat_reverse_charge_credit']) ? $vatdata['accountancy_code_vat_reverse_charge_credit'] : $rcctva); - $rcd_compta_tva = (!empty($vatdata['accountancy_code_vat_reverse_charge_debit']) ? $vatdata['accountancy_code_vat_reverse_charge_debit'] : $rcdtva); - $rcc_compta_localtax1 = (!empty($vatdata['accountancy_code_vat_reverse_charge_credit']) ? $vatdata['accountancy_code_vat_reverse_charge_credit'] : $rcctva); - $rcd_compta_localtax1 = (!empty($vatdata['accountancy_code_vat_reverse_charge_debit']) ? $vatdata['accountancy_code_vat_reverse_charge_debit'] : $rcdtva); - $rcc_compta_localtax2 = (!empty($vatdata['accountancy_code_vat_reverse_charge_credit']) ? $vatdata['accountancy_code_vat_reverse_charge_credit'] : $rcctva); - $rcd_compta_localtax2 = (!empty($vatdata['accountancy_code_vat_reverse_charge_debit']) ? $vatdata['accountancy_code_vat_reverse_charge_debit'] : $rcdtva); - if (price2num($obj->product_buy_vat) || !empty($obj->product_buy_default_vat_code)) { - $vat_key = vatrate($obj->product_buy_vat) . ($obj->product_buy_default_vat_code ? ' (' . $obj->product_buy_default_vat_code . ')' : ''); - $val_value = $vat_key; - $def_tva[$obj->rowid][$rcc_compta_tva][$vat_key] = $val_value; - $def_tva[$obj->rowid][$rcd_compta_tva][$vat_key] = $val_value; - } - - if (!isset($tabrctva[$obj->rowid][$rcc_compta_tva])) { - $tabrctva[$obj->rowid][$rcc_compta_tva] = 0; - } - if (!isset($tabrctva[$obj->rowid][$rcd_compta_tva])) { - $tabrctva[$obj->rowid][$rcd_compta_tva] = 0; - } - if (!isset($tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1])) { - $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] = 0; - } - if (!isset($tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1])) { - $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] = 0; - } - if (!isset($tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2])) { - $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] = 0; - } - if (!isset($tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2])) { - $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] = 0; - } - - $rcvat = (float) price2num($obj->total_ttc * $obj->product_buy_vat / 100, 'MT'); - $rclocalvat1 = (float) price2num($obj->total_ttc * $obj->product_buy_localvat1 / 100, 'MT'); - $rclocalvat2 = (float) price2num($obj->total_ttc * $obj->product_buy_localvat2 / 100, 'MT'); - - $tabrctva[$obj->rowid][$rcd_compta_tva] += $rcvat; - $tabrctva[$obj->rowid][$rcc_compta_tva] -= $rcvat; - $tabrclocaltax1[$obj->rowid][$rcd_compta_localtax1] += $rclocalvat1; - $tabrclocaltax1[$obj->rowid][$rcc_compta_localtax1] -= $rclocalvat1; - $tabrclocaltax2[$obj->rowid][$rcd_compta_localtax2] += $rclocalvat2; - $tabrclocaltax2[$obj->rowid][$rcc_compta_localtax2] -= $rclocalvat2; - } + if (!isset($tabttc[$obj->rowid][$compta_soc])) $tabttc[$obj->rowid][$compta_soc] = 0; + if (!isset($tabht[$obj->rowid][$compta_prod])) $tabht[$obj->rowid][$compta_prod] = 0; + if (!isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0; + if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) $tablocaltax1[$obj->rowid][$compta_localtax1] = 0; + if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) $tablocaltax2[$obj->rowid][$compta_localtax2] = 0; @@ -317,2 +194,2 @@ - $tva_npr = (($obj->info_bits & 1 == 1) ? 1 : 0); - if ($tva_npr) { // If NPR, we add an entry for counterpartWe into tabother + if (!empty($line->tva_npr)) // Add an entry for counterpart + { @@ -336,6 +212,0 @@ -// Check for too many invoices first. -if (count($tabfac) > 10000) { // Global config in htdocs/admin/const.php??? - $error++; - setEventMessages("TooManyInvoicesToProcessPleaseUseAMoreSelectiveFilter", null, 'errors'); -} - @@ -344,2 +214,0 @@ -/* -// Old way, 1 query for each invoice @@ -351 +220 @@ - $sql .= " AND fd.total_ttc <> 0 AND fk_facture_fourn = ".((int) $key); + $sql .= " AND fd.total_ttc <> 0 AND fk_facture_fourn = ".$key; @@ -353 +222,2 @@ - if ($resql) { + if ($resql) + { @@ -355 +225,2 @@ - if ($obj->nb > 0) { + if ($obj->nb > 0) + { @@ -358,29 +229,2 @@ - } else { - dol_print_error($db); - } -} -*/ -// New way, single query, load all unbound lines -$sql = " -SELECT - fk_facture_fourn, - COUNT(fd.rowid) as nb -FROM - llx_facture_fourn_det as fd -WHERE - fd.product_type <= 2 - AND fd.fk_code_ventilation <= 0 - AND fd.total_ttc <> 0 - AND fk_facture_fourn IN (".$db->sanitize(join(",", array_keys($tabfac))).") -GROUP BY fk_facture_fourn -"; -$resql = $db->query($sql); - -$num = $db->num_rows($resql); -$i = 0; -while ($i < $num) { - $obj = $db->fetch_object($resql); - if ($obj->nb > 0) { - $errorforinvoice[$obj->fk_facture_fourn] = 'somelinesarenotbound'; - } - $i++; + } + else dol_print_error($db); @@ -393 +237 @@ -if ($action == 'writebookkeeping' && !$error) { +if ($action == 'writebookkeeping') { @@ -399,3 +242,0 @@ - $accountingaccountsupplier = new AccountingAccount($db); - - $accountingaccountsupplier->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), true); @@ -412,0 +254 @@ + $companystatic->code_compta = $tabcompany[$key]['code_compta']; @@ -413,0 +256 @@ + $companystatic->code_client = $tabcompany[$key]['code_client']; @@ -428 +271,2 @@ - if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) { + if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) + { @@ -431,3 +275 @@ - if ($alreadydispatched) { - $replacedinvoice = 2; - } + if ($alreadydispatched) $replacedinvoice = 2; @@ -437 +279,2 @@ - if ($replacedinvoice == 1) { + if ($replacedinvoice == 1) + { @@ -443 +286,2 @@ - if ($errorforinvoice[$key] == 'somelinesarenotbound') { + if ($errorforinvoice[$key] == 'somelinesarenotbound') + { @@ -450 +294,2 @@ - if (!$errorforline) { + if (!$errorforline) + { @@ -461 +305,0 @@ - @@ -464,3 +308,4 @@ - - $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'); - $bookkeeping->label_compte = $accountingaccountsupplier->label; + $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; + + $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -474 +319 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -483 +328,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -488 +334,3 @@ - } else { + } + else + { @@ -494,7 +341,0 @@ - } else { - if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) { - require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; - $lettering_static = new Lettering($db); - - $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id)); - } @@ -506 +347,2 @@ - if (!$errorforline) { + if (!$errorforline) + { @@ -508,3 +349,0 @@ - $resultfetch = $accountingaccount->fetch(null, $k, true); // TODO Use a cache - $label_account = $accountingaccount->label; - @@ -512 +351 @@ - if ($resultfetch > 0) { + if ($accountingaccount->fetch(null, $k, true)) { @@ -522,14 +361,2 @@ - - if (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) { - if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT')) { - $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; - $bookkeeping->subledger_label = $tabcompany[$key]['name']; - } else { - $bookkeeping->subledger_account = ''; - $bookkeeping->subledger_label = ''; - } - } else { - $bookkeeping->subledger_account = ''; - $bookkeeping->subledger_label = ''; - } - + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; @@ -537,3 +364,2 @@ - $bookkeeping->label_compte = $label_account; - - $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref_supplier.' - '.$label_account; + $bookkeeping->label_compte = $accountingaccount->label; + $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref_supplier.' - '.$accountingaccount->label; @@ -545 +371 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -554 +380,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -559 +386,3 @@ - } else { + } + else + { @@ -572 +401,2 @@ - if (!$errorforline) { + if (!$errorforline) + { @@ -574 +404,2 @@ - foreach ($listoftax as $numtax) { + foreach ($listoftax as $numtax) + { @@ -576,29 +407,2 @@ - if ($numtax == 1) { - $arrayofvat = $tablocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tablocaltax2; - } - - // VAT Reverse charge - if ($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) { - $has_vat = false; - foreach ($arrayofvat[$key] as $k => $mt) { - if ($mt) { - $has_vat = true; - } - } - - if (!$has_vat) { - $arrayofvat = $tabrctva; - if ($numtax == 1) { - $arrayofvat = $tabrclocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tabrclocaltax2; - } - if (!is_array($arrayofvat[$key])) { - $arrayofvat[$key] = array(); - } - } - } + if ($numtax == 1) $arrayofvat = $tablocaltax1; + if ($numtax == 2) $arrayofvat = $tablocaltax2; @@ -608,3 +411,0 @@ - $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label - $label_account = $accountingaccount->label; - @@ -620 +420,0 @@ - @@ -623 +422,0 @@ - @@ -625 +424,3 @@ - $bookkeeping->label_compte = $label_account; + + $accountingaccount->fetch($k, null, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -633 +434 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -642 +443,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -647 +449,3 @@ - } else { + } + else + { @@ -661 +465,2 @@ - if (!$errorforline && is_array($tabother[$key])) { + if (!$errorforline && is_array($tabother[$key])) + { @@ -673 +477,0 @@ - @@ -676 +479,0 @@ - @@ -678 +480,0 @@ - @@ -685 +487 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -694 +496,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -699 +502,3 @@ - } else { + } + else + { @@ -711 +516,2 @@ - if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) { + if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) + { @@ -715,4 +521,5 @@ - setEventMessages('We tried to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors'); - } - - if (!$errorforline) { + setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors'); + } + + if (!$errorforline) + { @@ -720 +527,3 @@ - } else { + } + else + { @@ -723 +532,2 @@ - if ($error >= 10) { + if ($error >= 10) + { @@ -734 +544,3 @@ - } elseif (count($tabpay) == $error) { + } + elseif (count($tabpay) == $error) + { @@ -736 +548,3 @@ - } else { + } + else + { @@ -743 +557,2 @@ - if (count($tabpay) != $error) { + if (count($tabpay) != $error) + { @@ -764,2 +579,2 @@ -if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 ! - $sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV'); +if ($action == 'exportcsv') { // ISO and not UTF8 ! + $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; @@ -774 +589,2 @@ - foreach ($tabfac as $key => $val) { + foreach ($tabfac as $key => $val) + { @@ -776,0 +593 @@ + $companystatic->code_compta = $tabcompany[$key]['code_compta']; @@ -777,0 +595 @@ + $companystatic->code_client = $tabcompany[$key]['code_client']; @@ -792 +610,2 @@ - if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) { + if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) + { @@ -795,3 +614 @@ - if ($alreadydispatched) { - $replacedinvoice = 2; - } + if ($alreadydispatched) $replacedinvoice = 2; @@ -801 +618,2 @@ - if ($replacedinvoice == 1) { + if ($replacedinvoice == 1) + { @@ -808,13 +626,13 @@ - print '"'.$key.'"'.$sep; - print '"'.$date.'"'.$sep; - print '"'.$val["refsologest"].'"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 32), 'ISO-8859-1').'"'.$sep; - print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; - print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')).'"'.$sep; - print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; - print '"'.$langs->trans("Thirdparty").'"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 16), 'ISO-8859-1').' - '.$val["refsuppliersologest"].' - '.$langs->trans("Thirdparty").'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; - print '"'.$journal.'"'; - print "\n"; + print '"'.$key.'"'.$sep; + print '"'.$date.'"'.$sep; + print '"'.$val["refsologest"].'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; + print '"'.$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER.'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; + print '"'.$langs->trans("Thirdparty").'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$val["refsuppliersologest"].' - '.$langs->trans("Thirdparty").'"'.$sep; + print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; + print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; + print '"'.$journal.'"'; + print "\n"; @@ -829,13 +647,13 @@ - print '"'.$key.'"'.$sep; - print '"'.$date.'"'.$sep; - print '"'.$val["refsologest"].'"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 32), 'ISO-8859-1').'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '""'.$sep; - print '"'.mb_convert_encoding(dol_trunc($accountingaccount->label, 32), 'ISO-8859-1').'"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 16), 'ISO-8859-1').' - '.$val["refsuppliersologest"].' - '.dol_trunc($accountingaccount->label, 32).'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; - print '"'.$journal.'"'; - print "\n"; + print '"'.$key.'"'.$sep; + print '"'.$date.'"'.$sep; + print '"'.$val["refsologest"].'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep; + print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '""'.$sep; + print '"'.utf8_decode(dol_trunc($accountingaccount->label, 32)).'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$val["refsuppliersologest"].' - '.dol_trunc($accountingaccount->label, 32).'"'.$sep; + print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; + print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; + print '"'.$journal.'"'; + print "\n"; @@ -849,29 +667,2 @@ - if ($numtax == 1) { - $arrayofvat = $tablocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tablocaltax2; - } - - // VAT Reverse charge - if ($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) { - $has_vat = false; - foreach ($arrayofvat[$key] as $k => $mt) { - if ($mt) { - $has_vat = true; - } - } - - if (!$has_vat) { - $arrayofvat = $tabrctva; - if ($numtax == 1) { - $arrayofvat = $tabrclocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tabrclocaltax2; - } - if (!is_array($arrayofvat[$key])) { - $arrayofvat[$key] = array(); - } - } - } + if ($numtax == 1) $arrayofvat = $tablocaltax1; + if ($numtax == 2) $arrayofvat = $tablocaltax2; @@ -884 +675 @@ - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 32), 'ISO-8859-1').'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep; @@ -888,2 +679,2 @@ - print '"'.$langs->trans("VAT").' - '.join(', ', $def_tva[$key][$k]).' %"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 16), 'ISO-8859-1').' - '.$val["refsuppliersologest"].' - '.$langs->trans("VAT").join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '').'"'.$sep; + print '"'.$langs->trans("VAT").' - '.$def_tva[$key].'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$val["refsuppliersologest"].' - '.$langs->trans("VAT").join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '').'"'.$sep; @@ -898 +689,2 @@ - if (is_array($tabother[$key])) { + if (is_array($tabother[$key])) + { @@ -904,4 +696,4 @@ - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 32), 'ISO-8859-1').'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; + print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; @@ -909 +701 @@ - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 16), 'ISO-8859-1').' - '.$val["refsuppliersologest"].' - '.$langs->trans("VAT").' NPR"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$val["refsuppliersologest"].' - '.$langs->trans("VAT").' NPR"'.$sep; @@ -922,5 +714,3 @@ - $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1); - - llxHeader('', dol_string_nohtmltag($title)); - - $nom = $title; + llxHeader('', $langs->trans("PurchasesJournal")); + + $nom = $langs->trans("PurchasesJournal").' | '.$accountingjournalstatic->getNomUrl(0, 1, 1, '', 1); @@ -931,2 +721,2 @@ - $description = $langs->trans("DescJournalOnlyBindedVisible").'
'; - if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { + $description .= $langs->trans("DescJournalOnlyBindedVisible").'
'; + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { @@ -939,2 +729,2 @@ - $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0); - $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); + $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0); + $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); @@ -946,19 +735,0 @@ - if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') != 'blockedonclosed') { - // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed) - // Fiscal period test - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE entity = ".((int) $conf->entity); - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - if ($obj->nb == 0) { - print '
'.img_warning().' '.$langs->trans("TheFiscalPeriodIsNotDefined"); - $desc = ' : '.$langs->trans("AccountancyAreaDescFiscalPeriod", 4, '{link}'); - $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("FiscalPeriod").'', $desc); - print $desc; - print '
'; - } - } else { - dol_print_error($db); - } - } - @@ -966,13 +737,8 @@ - $acctSupplierNotConfigured = in_array(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), ['','-1']); - if ($acctSupplierNotConfigured) { - print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); - $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}'); - $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'', $desc); - print $desc; - print '
'; - } - print '
'; - if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') { - print ''; - } - if ($acctSupplierNotConfigured) { + if (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == "") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1') { + print '
'; + print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + } + print '
'; + if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') print ''; + if (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == "") || $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER == '-1') { @@ -980,6 +746,4 @@ - } else { - if ($in_bookkeeping == 'notyet') { - print ''; - } else { - print ''.$langs->trans("WriteBookKeeping").''; - } + } + else { + if ($in_bookkeeping == 'notyet') print ''; + else print ''.$langs->trans("WriteBookKeeping").''; @@ -1009,0 +774 @@ + $i = 0; @@ -1018,2 +783,2 @@ - print '
"; - print '"; + print '"; + print '"; @@ -1022 +787 @@ - $i = 0; + $r = ''; @@ -1027 +792,2 @@ - foreach ($tabfac as $key => $val) { + foreach ($tabfac as $key => $val) + { @@ -1029,0 +796 @@ + $companystatic->code_compta = $tabcompany[$key]['code_compta']; @@ -1030,0 +798 @@ + $companystatic->code_client = $tabcompany[$key]['code_client']; @@ -1045 +813,2 @@ - if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) { + if ($invoicestatic->close_code == FactureFournisseur::CLOSECODE_REPLACED) + { @@ -1048,3 +817 @@ - if ($alreadydispatched) { - $replacedinvoice = 2; - } + if ($alreadydispatched) $replacedinvoice = 2; @@ -1054 +821,2 @@ - if ($replacedinvoice == 1) { + if ($replacedinvoice == 1) + { @@ -1072 +839,0 @@ - $i++; @@ -1075 +842,2 @@ - if ($errorforinvoice[$key] == 'somelinesarenotbound') { + if ($errorforinvoice[$key] == 'somelinesarenotbound') + { @@ -1092,2 +859,0 @@ - - $i++; @@ -1104,2 +870,3 @@ - $accountoshow = length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER')); - if (($accountoshow == "") || $accountoshow == 'NotDefined') { + $accountoshow = length_accounta($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER); + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { @@ -1107,3 +874,2 @@ - } else { - print $accountoshow; - } + } + else print $accountoshow; @@ -1114 +880,2 @@ - if (($accountoshow == "") || $accountoshow == 'NotDefined') { + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { @@ -1116,3 +883,2 @@ - } else { - print $accountoshow; - } + } + else print $accountoshow; @@ -1121,2 +887,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -1124,2 +889,0 @@ - - $i++; @@ -1140 +904,2 @@ - if (($accountoshow == "") || $accountoshow == 'NotDefined') { + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { @@ -1142,3 +907,2 @@ - } else { - print $accountoshow; - } + } + else print $accountoshow; @@ -1148,7 +911,0 @@ - if (getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) { - if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT')) { - print length_accounta($tabcompany[$key]['code_compta']); - } - } elseif (($accountoshow == "") || $accountoshow == 'NotDefined') { - print '' . $langs->trans("ThirdpartyAccountNotDefined") . ''; - } @@ -1159,2 +916,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -1162,2 +918,0 @@ - - $i++; @@ -1170,29 +925,2 @@ - if ($numtax == 1) { - $arrayofvat = $tablocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tablocaltax2; - } - - // VAT Reverse charge - if ($mysoc->country_code == 'FR' || getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) { - $has_vat = false; - foreach ($arrayofvat[$key] as $k => $mt) { - if ($mt) { - $has_vat = true; - } - } - - if (!$has_vat) { - $arrayofvat = $tabrctva; - if ($numtax == 1) { - $arrayofvat = $tabrclocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tabrclocaltax2; - } - if (!is_array($arrayofvat[$key])) { - $arrayofvat[$key] = array(); - } - } - } + if ($numtax == 1) $arrayofvat = $tablocaltax1; + if ($numtax == 2) $arrayofvat = $tablocaltax2; @@ -1209,4 +937,3 @@ - if (($accountoshow == "") || $accountoshow == 'NotDefined') { - print ''.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("AccountingJournalType3").')'; - } else { - print $accountoshow; + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { + print ''.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("Purchase").')'; @@ -1213,0 +941 @@ + else print $accountoshow; @@ -1221,2 +949,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -1224,2 +951,0 @@ - - $i++; @@ -1231 +957,2 @@ - if (is_array($tabother[$key])) { + if (is_array($tabother[$key])) + { @@ -1241 +968,2 @@ - if ($accountoshow == '' || $accountoshow == 'NotDefined') { + if ($accountoshow == '' || $accountoshow == 'NotDefined') + { @@ -1243,2 +970,0 @@ - } else { - print $accountoshow; @@ -1245,0 +972 @@ + else print $accountoshow; @@ -1251,2 +978,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -1254,2 +980,0 @@ - - $i++; @@ -1259,4 +983,0 @@ - } - - if (!$i) { - print ''; --- /tmp/dsg/dolibarr/htdocs/accountancy/journal/github_19.0.3_sellsjournal.php +++ /tmp/dsg/dolibarr/htdocs/accountancy/journal/client_sellsjournal.php @@ -7 +7 @@ - * Copyright (C) 2013-2023 Alexandre Spangaro + * Copyright (C) 2013-2018 Alexandre Spangaro @@ -11 +11 @@ - * Copyright (C) 2018-2021 Frédéric France + * Copyright (C) 2018 Frédéric France @@ -33 +32,0 @@ -// Load Dolibarr environment @@ -57,3 +56 @@ -if ($in_bookkeeping == '') { - $in_bookkeeping = 'notyet'; -} +if ($in_bookkeeping == '') $in_bookkeeping = 'notyet'; @@ -61,0 +59,4 @@ + +// Security check +if ($user->socid > 0) + accessforbidden(); @@ -65,14 +65,0 @@ - -// Security check -if (!isModEnabled('accounting')) { - accessforbidden(); -} -if ($user->socid > 0) { - accessforbidden(); -} -if (!$user->hasRight('accounting', 'mouvements', 'lire')) { - accessforbidden(); -} - -$error = 0; - @@ -93,0 +81,8 @@ +$year_current = strftime("%Y", dol_now()); +$pastmonth = strftime("%m", dol_now()) - 1; +$pastmonthyear = $year_current; +if ($pastmonth == 0) { + $pastmonth = 12; + $pastmonthyear--; +} + @@ -97,19 +92,2 @@ -if (empty($date_startmonth)) { - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_start = $dates['date_start']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} -if (empty($date_endmonth)) { - // Period by default on transfer - $dates = getDefaultDatesForTransfer(); - $date_end = $dates['date_end']; - $pastmonthyear = $dates['pastmonthyear']; - $pastmonth = $dates['pastmonth']; -} -if (getDolGlobalString('ACCOUNTANCY_JOURNAL_USE_CURRENT_MONTH')) { - $pastmonth+=1; -} - -if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) { // We define date_start and date_end, only if we did not submit the form +if (!GETPOSTISSET('date_startmonth') && (empty($date_start) || empty($date_end))) // We define date_start and date_end, only if we did not submit the form +{ @@ -120,19 +98,4 @@ -$sql = "SELECT f.rowid, f.ref, f.type, f.situation_cycle_ref, f.datef as df, f.ref_client, f.date_lim_reglement as dlr, f.close_code, f.retained_warranty, f.revenuestamp,"; -$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code, fd.info_bits,"; -$sql .= " s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur,"; -if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { - $sql .= " spe.accountancy_code_customer as code_compta,"; - $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; -} else { - $sql .= " s.code_compta as code_compta,"; - $sql .= " s.code_compta_fournisseur,"; -} -$sql .= " p.rowid as pid, p.ref as pref, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,"; -if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { - $sql .= " ppe.accountancy_code_sell"; -} else { - $sql .= " p.accountancy_code_sell"; -} -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; +$sql = "SELECT f.rowid, f.ref, f.type, f.datef as df, f.ref_client, f.date_lim_reglement as dlr, f.close_code,"; +$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.total_localtax1, fd.total_localtax2, fd.tva_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code,"; +$sql .= " s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,"; +$sql .= " p.rowid as pid, p.ref as pref, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; @@ -141,3 +103,0 @@ -if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); -} @@ -147,6 +106,0 @@ -if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); -} -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; @@ -156 +110 @@ -if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { // Non common setup +if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { // Non common setup @@ -162 +116 @@ -if ($date_start && $date_end) { +if ($date_start && $date_end) @@ -164,5 +117,0 @@ -} -// Define begin binding date -if (getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) { - $sql .= " AND f.datef >= '".$db->idate(getDolGlobalString('ACCOUNTING_DATE_START_BINDING'))."'"; -} @@ -170 +119,2 @@ -if ($in_bookkeeping == 'already') { +if ($in_bookkeeping == 'already') +{ @@ -174 +124,2 @@ -if ($in_bookkeeping == 'notyet') { +if ($in_bookkeeping == 'notyet') +{ @@ -176 +127 @@ - // $sql .= " AND fd.rowid NOT IN (SELECT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')"; // Useless, we save one line for all products with same account + // $sql .= " AND fd.rowid NOT IN (SELECT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice')"; // Useless, we save one line for all products with same account @@ -178,4 +129 @@ -$parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook -$sql .= $hookmanager->resPrint; -$sql .= " ORDER BY f.datef, f.ref"; +$sql .= " ORDER BY f.datef"; @@ -191,2 +138,0 @@ - $tabwarranty = array(); - $tabrevenuestamp = array(); @@ -197 +142,0 @@ - $vatdata_cache = array(); @@ -202,2 +147,2 @@ - $cptcli = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER', 'NotDefined'); - $cpttva = getDolGlobalString('ACCOUNTING_VAT_SOLD_ACCOUNT', 'NotDefined'); + $cptcli = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER != "")) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : 'NotDefined'; + $cpttva = (!empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : 'NotDefined'; @@ -214,16 +159,7 @@ - if ($obj->product_type == 0) { - $compta_prod = getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_ACCOUNT', 'NotDefined'); - } else { - $compta_prod = getDolGlobalString('ACCOUNTING_SERVICE_SOLD_ACCOUNT', 'NotDefined'); - } - } - - //$compta_revenuestamp = getDolGlobalString('ACCOUNTING_REVENUESTAMP_SOLD_ACCOUNT', 'NotDefined'); - - $tax_id = $obj->tva_tx . ($obj->vat_src_code ? ' (' . $obj->vat_src_code . ')' : ''); - if (array_key_exists($tax_id, $vatdata_cache)) { - $vatdata = $vatdata_cache[$tax_id]; - } else { - $vatdata = getTaxesFromId($tax_id, $mysoc, $mysoc, 0); - $vatdata_cache[$tax_id] = $vatdata; - } + if ($obj->product_type == 0) + $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : 'NotDefined'; + else + $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : 'NotDefined'; + } + + $vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), $mysoc, $mysoc, 0); @@ -234,2 +170,3 @@ - // Define the array to store the detail of each vat rate and code for lines - if (price2num($obj->tva_tx) || !empty($obj->vat_src_code)) { + // Define array to display all VAT rates that use this accounting account $compta_tva + if (price2num($obj->tva_tx) || !empty($obj->vat_src_code)) + { @@ -239,16 +176,12 @@ - // Create a compensation rate for situation invoice. - $situation_ratio = 1; - if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) { - if ($obj->situation_cycle_ref) { - // Avoid divide by 0 - if ($obj->situation_percent == 0) { - $situation_ratio = 0; - } else { - $line = new FactureLigne($db); - $line->fetch($obj->fdid); - - // Situation invoices handling - $prev_progress = $line->get_prev_progress($obj->rowid); - - $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent; - } + $line = new FactureLigne($db); + $line->fetch($obj->fdid); + + // Situation invoices handling + $prev_progress = $line->get_prev_progress($obj->rowid); + + if ($obj->type == Facture::TYPE_SITUATION) { + // Avoid divide by 0 + if ($obj->situation_percent == 0) { + $situation_ratio = 0; + } else { + $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent; @@ -256,3 +189,3 @@ - } - - $revenuestamp = (float) price2num($obj->revenuestamp, 'MT'); + } else { + $situation_ratio = 1; + } @@ -267 +199,0 @@ - $tabfac[$obj->rowid]["revenuestamp"] = $revenuestamp; @@ -271,35 +203,7 @@ - if (!isset($tabttc[$obj->rowid][$compta_soc])) { - $tabttc[$obj->rowid][$compta_soc] = 0; - } - if (!isset($tabht[$obj->rowid][$compta_prod])) { - $tabht[$obj->rowid][$compta_prod] = 0; - } - if (!isset($tabtva[$obj->rowid][$compta_tva])) { - $tabtva[$obj->rowid][$compta_tva] = 0; - } - if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) { - $tablocaltax1[$obj->rowid][$compta_localtax1] = 0; - } - if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) { - $tablocaltax2[$obj->rowid][$compta_localtax2] = 0; - } - - // Compensation of data for invoice situation by using $situation_ratio. This works (nearly) for invoice that was not correctly recorded - // but it may introduces an error for situation invoices that were correctly saved. There is still rounding problem that differs between - // real data we should have stored and result obtained with a compensation. - // It also seems that credit notes on situation invoices are correctly saved (but it depends on the version used in fact). - // For credit notes, we hope to have situation_ratio = 1 so the compensation has no effect to avoid introducing troubles with credit notes. - if (getDolGlobalInt('INVOICE_USE_SITUATION') == 1) { - $total_ttc = $obj->total_ttc * $situation_ratio; - } else { - $total_ttc = $obj->total_ttc; - } - - // Move a part of the retained warrenty into the account of warranty - if (getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY') && $obj->retained_warranty > 0) { - $retained_warranty = (float) price2num($total_ttc * $obj->retained_warranty / 100, 'MT'); // Calculate the amount of warrenty for this line (using the percent value) - $tabwarranty[$obj->rowid][$compta_soc] += $retained_warranty; - $total_ttc -= $retained_warranty; - } - - $tabttc[$obj->rowid][$compta_soc] += $total_ttc; + if (!isset($tabttc[$obj->rowid][$compta_soc])) $tabttc[$obj->rowid][$compta_soc] = 0; + if (!isset($tabht[$obj->rowid][$compta_prod])) $tabht[$obj->rowid][$compta_prod] = 0; + if (!isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0; + if (!isset($tablocaltax1[$obj->rowid][$compta_localtax1])) $tablocaltax1[$obj->rowid][$compta_localtax1] = 0; + if (!isset($tablocaltax2[$obj->rowid][$compta_localtax2])) $tablocaltax2[$obj->rowid][$compta_localtax2] = 0; + + $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio; @@ -307,4 +211 @@ - $tva_npr = (($obj->info_bits & 1 == 1) ? 1 : 0); - if (!$tva_npr) { // We ignore line if VAT is a NPR - $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio; - } + if (empty($line->tva_npr)) $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio; // We ignore line if VAT is a NPR @@ -313,28 +213,0 @@ - - $compta_revenuestamp = 'NotDefined'; - if (!empty($revenuestamp)) { - $sqlrevenuestamp = "SELECT accountancy_code_sell FROM ".MAIN_DB_PREFIX."c_revenuestamp"; - $sqlrevenuestamp .= " WHERE fk_pays = ".((int) $mysoc->country_id); - $sqlrevenuestamp .= " AND taux = ".((float) $revenuestamp); - $sqlrevenuestamp .= " AND active = 1"; - $resqlrevenuestamp = $db->query($sqlrevenuestamp); - - if ($resqlrevenuestamp) { - $num_rows_revenuestamp = $db->num_rows($resqlrevenuestamp); - if ($num_rows_revenuestamp > 1) { - dol_print_error($db, 'Failed 2 or more lines for the revenue stamp of your country. Check the dictionary of revenue stamp.'); - } else { - $objrevenuestamp = $db->fetch_object($resqlrevenuestamp); - if ($objrevenuestamp) { - $compta_revenuestamp = $objrevenuestamp->accountancy_code_sell; - } - } - } - } - - if (empty($tabrevenuestamp[$obj->rowid][$compta_revenuestamp]) && !empty($revenuestamp)) { - // The revenue stamp was never seen for this invoice id=$obj->rowid - $tabttc[$obj->rowid][$compta_soc] += $obj->revenuestamp; - $tabrevenuestamp[$obj->rowid][$compta_revenuestamp] = $obj->revenuestamp; - } - @@ -350,2 +222,0 @@ - - // After the loop on each line @@ -356,6 +226,0 @@ -// Check for too many invoices first. -if (count($tabfac) > 10000) { - $error++; - setEventMessages("TooManyInvoicesToProcessPleaseUseAMoreSelectiveFilter", null, 'errors'); -} - @@ -364,3 +229 @@ -/* -// Old way, 1 query for each invoice -// Loop on all invoices to detect lines without binded code (fk_code_ventilation <= 0) +// Loop in invoices to detect lines with not binding lines @@ -371 +234 @@ - $sql .= " AND fd.total_ttc <> 0 AND fk_facture = ".((int) $key); + $sql .= " AND fd.total_ttc <> 0 AND fk_facture = ".$key; @@ -373 +236,2 @@ - if ($resql) { + if ($resql) + { @@ -375 +239,2 @@ - if ($obj->nb > 0) { + if ($obj->nb > 0) + { @@ -378,30 +243,2 @@ - } else { - dol_print_error($db); - } -} -*/ -// New way, single query, load all unbound lines - -$sql = " -SELECT - fk_facture, - COUNT(fd.rowid) as nb -FROM - ".MAIN_DB_PREFIX."facturedet as fd -WHERE - fd.product_type <= 2 - AND fd.fk_code_ventilation <= 0 - AND fd.total_ttc <> 0 - AND fk_facture IN (".$db->sanitize(join(",", array_keys($tabfac))).") -GROUP BY fk_facture -"; -$resql = $db->query($sql); - -$num = $db->num_rows($resql); -$i = 0; -while ($i < $num) { - $obj = $db->fetch_object($resql); - if ($obj->nb > 0) { - $errorforinvoice[$obj->fk_facture_fourn] = 'somelinesarenotbound'; - } - $i++; + } + else dol_print_error($db); @@ -410,0 +248 @@ + @@ -412 +250 @@ -if ($action == 'writebookkeeping' && !$error) { +if ($action == 'writebookkeeping') { @@ -418,7 +255,0 @@ - $accountingaccountcustomer = new AccountingAccount($db); - - $accountingaccountcustomer->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true); - - $accountingaccountcustomerwarranty = new AccountingAccount($db); - - $accountingaccountcustomerwarranty->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'), true); @@ -437 +268 @@ - $companystatic->code_compta_client = $tabcompany[$key]['code_compta']; + $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; @@ -438,0 +270 @@ + $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; @@ -450 +282,2 @@ - if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) { + if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) + { @@ -453,3 +286 @@ - if ($alreadydispatched) { - $replacedinvoice = 2; - } + if ($alreadydispatched) $replacedinvoice = 2; @@ -459 +290,2 @@ - if ($replacedinvoice == 1) { + if ($replacedinvoice == 1) + { @@ -465 +297,2 @@ - if ($errorforinvoice[$key] == 'somelinesarenotbound') { + if ($errorforinvoice[$key] == 'somelinesarenotbound') + { @@ -471,51 +303,0 @@ - // Warranty - if (!$errorforline && getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key])) { - if (is_array($tabwarranty[$key])) { - foreach ($tabwarranty[$key] as $k => $mt) { - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->date_lim_reglement = $val["datereg"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->date_creation = $now; - $bookkeeping->doc_type = 'customer_invoice'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add - $bookkeeping->thirdparty_code = $companystatic->code_client; - - $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; - $bookkeeping->subledger_label = $tabcompany[$key]['name']; - - $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'); - $bookkeeping->label_compte = $accountingaccountcustomerwarranty->label; - - $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Retainedwarranty"); - $bookkeeping->montant = $mt; - $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C'; - $bookkeeping->debit = ($mt >= 0) ? $mt : 0; - $bookkeeping->credit = ($mt < 0) ? -$mt : 0; - $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); - $bookkeeping->fk_user_author = $user->id; - $bookkeeping->entity = $conf->entity; - - $totaldebit += $bookkeeping->debit; - $totalcredit += $bookkeeping->credit; - - $result = $bookkeeping->create($user); - if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists - $error++; - $errorforline++; - $errorforinvoice[$key] = 'alreadyjournalized'; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { - $error++; - $errorforline++; - $errorforinvoice[$key] = 'other'; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); - } - } - } - } - } - @@ -523 +305,2 @@ - if (!$errorforline) { + if (!$errorforline) + { @@ -534 +316,0 @@ - @@ -537,3 +319,4 @@ - - $bookkeeping->numero_compte = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'); - $bookkeeping->label_compte = $accountingaccountcustomer->label; + $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; + + $accountingaccount->fetch(null, $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, true); + $bookkeeping->label_compte = $accountingaccount->label; @@ -547 +330 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -556 +339,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -561 +345,3 @@ - } else { + } + else + { @@ -567,7 +352,0 @@ - } else { - if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && getDolGlobalInt('ACCOUNTING_ENABLE_AUTOLETTERING')) { - require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; - $lettering_static = new Lettering($db); - - $nb_lettering = $lettering_static->bookkeepingLettering(array($bookkeeping->id)); - } @@ -579 +358,2 @@ - if (!$errorforline) { + if (!$errorforline) + { @@ -581,3 +360,0 @@ - $resultfetch = $accountingaccount->fetch(null, $k, true); // TODO Use a cache - $label_account = $accountingaccount->label; - @@ -585 +362 @@ - if ($resultfetch > 0) { + if ($accountingaccount->fetch(null, $k, true)) { @@ -595,14 +372,2 @@ - - if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) { - if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT')) { - $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; - $bookkeeping->subledger_label = $tabcompany[$key]['name']; - } else { - $bookkeeping->subledger_account = ''; - $bookkeeping->subledger_label = ''; - } - } else { - $bookkeeping->subledger_account = ''; - $bookkeeping->subledger_label = ''; - } - + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; @@ -610,3 +375,2 @@ - $bookkeeping->label_compte = $label_account; - - $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$label_account; + $bookkeeping->label_compte = $accountingaccount->label; + $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$accountingaccount->label; @@ -618 +382 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -627 +391,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -632 +397,3 @@ - } else { + } + else + { @@ -644 +411,2 @@ - if (!$errorforline) { + if (!$errorforline) + { @@ -646 +414,2 @@ - foreach ($listoftax as $numtax) { + foreach ($listoftax as $numtax) + { @@ -648,6 +417,2 @@ - if ($numtax == 1) { - $arrayofvat = $tablocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tablocaltax2; - } + if ($numtax == 1) $arrayofvat = $tablocaltax1; + if ($numtax == 2) $arrayofvat = $tablocaltax2; @@ -657,3 +421,0 @@ - $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label - $label_account = $accountingaccount->label; - @@ -669 +430,0 @@ - @@ -672 +432,0 @@ - @@ -674,8 +434,5 @@ - $bookkeeping->label_compte = $label_account; - - - $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref; - $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ? '' : $arrayofvat[$key][$k]) : join(', ', $def_tva[$key][$k])); - $bookkeeping->label_operation .= ' - '.$langs->trans("Taxes").' '.$tmpvatrate.' %'; - $bookkeeping->label_operation .= ($numtax ? ' - Localtax '.$numtax : ''); - + + $accountingaccount->fetch($k, null, true); + $bookkeeping->label_compte = $accountingaccount->label; + + $bookkeeping->label_operation = dol_trunc($companystatic->name, 16).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").' '.join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : ''); @@ -687 +444 @@ - $bookkeeping->journal_label = $langs->transnoentities($journal_label); + $bookkeeping->journal_label = $journal_label; @@ -696 +453,2 @@ - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { @@ -701 +459,3 @@ - } else { + } + else + { @@ -713,56 +472,0 @@ - // Revenue stamp - if (!$errorforline) { - if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) { - foreach ($tabrevenuestamp[$key] as $k => $mt) { - if ($mt) { - $accountingaccount->fetch(null, $k, true); // TODO Use a cache for label - $label_account = $accountingaccount->label; - - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->date_lim_reglement = $val["datereg"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->date_creation = $now; - $bookkeeping->doc_type = 'customer_invoice'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add - $bookkeeping->thirdparty_code = $companystatic->code_client; - - $bookkeeping->subledger_account = ''; - $bookkeeping->subledger_label = ''; - - $bookkeeping->numero_compte = $k; - $bookkeeping->label_compte = $label_account; - - $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("RevenueStamp"); - $bookkeeping->montant = $mt; - $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; - $bookkeeping->debit = ($mt < 0) ? -$mt : 0; - $bookkeeping->credit = ($mt >= 0) ? $mt : 0; - $bookkeeping->code_journal = $journal; - $bookkeeping->journal_label = $langs->transnoentities($journal_label); - $bookkeeping->fk_user_author = $user->id; - $bookkeeping->entity = $conf->entity; - - $totaldebit += $bookkeeping->debit; - $totalcredit += $bookkeeping->credit; - - $result = $bookkeeping->create($user); - if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') { // Already exists - $error++; - $errorforline++; - $errorforinvoice[$key] = 'alreadyjournalized'; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->fk_doc.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } else { - $error++; - $errorforline++; - $errorforinvoice[$key] = 'other'; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); - } - } - } - } - } - } - @@ -770 +474,2 @@ - if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) { + if (!$errorforline && (price2num($totaldebit, 'MT') != price2num($totalcredit, 'MT'))) + { @@ -774,4 +479,5 @@ - setEventMessages('We Tried to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors'); - } - - if (!$errorforline) { + setEventMessages('Try to insert a non balanced transaction in book for '.$invoicestatic->ref.'. Canceled. Surely a bug.', null, 'errors'); + } + + if (!$errorforline) + { @@ -779 +485,3 @@ - } else { + } + else + { @@ -782 +490,2 @@ - if ($error >= 10) { + if ($error >= 10) + { @@ -793 +502,3 @@ - } elseif (count($tabpay) == $error) { + } + elseif (count($tabpay) == $error) + { @@ -795 +506,3 @@ - } else { + } + else + { @@ -802 +515,2 @@ - if (count($tabpay) != $error) { + if (count($tabpay) != $error) + { @@ -825,3 +539,2 @@ -if ($action == 'exportcsv' && !$error) { // ISO and not UTF8 ! - // Note that to have the button to get this feature enabled, you must enable ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL - $sep = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV'); +if ($action == 'exportcsv') { // ISO and not UTF8 ! + $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; @@ -836 +549,2 @@ - foreach ($tabfac as $key => $val) { + foreach ($tabfac as $key => $val) + { @@ -839,2 +553,2 @@ - $companystatic->code_compta = $tabcompany[$key]['code_compta']; // deprecated - $companystatic->code_compta_client = $tabcompany[$key]['code_compta']; + $companystatic->code_compta = $tabcompany[$key]['code_compta']; + $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; @@ -841,0 +556 @@ + $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; @@ -853 +568,2 @@ - if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) { + if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) + { @@ -856,3 +572 @@ - if ($alreadydispatched) { - $replacedinvoice = 2; - } + if ($alreadydispatched) $replacedinvoice = 2; @@ -862 +576,2 @@ - if ($replacedinvoice == 1) { + if ($replacedinvoice == 1) + { @@ -866,4 +581,3 @@ - // Warranty - if (getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key])) { - foreach ($tabwarranty[$key] as $k => $mt) { - //if ($mt) { + // Third party + foreach ($tabttc[$key] as $k => $mt) { + //if ($mt) { @@ -873 +587 @@ - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 32), 'ISO-8859-1').'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep; @@ -875 +589 @@ - print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY')).'"'.$sep; + print '"'.$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER.'"'.$sep; @@ -878 +592 @@ - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 16), 'ISO-8859-1').' - '.$invoicestatic->ref.' - '.$langs->trans("Retainedwarranty").'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$invoicestatic->ref.' - '.$langs->trans("Thirdparty").'"'.$sep; @@ -883,20 +596,0 @@ - //} - } - } - - // Third party - foreach ($tabttc[$key] as $k => $mt) { - //if ($mt) { - print '"'.$key.'"'.$sep; - print '"'.$date.'"'.$sep; - print '"'.$val["ref"].'"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 32), 'ISO-8859-1').'"'.$sep; - print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; - print '"'.length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER')).'"'.$sep; - print '"'.length_accounta(html_entity_decode($k)).'"'.$sep; - print '"'.$langs->trans("Thirdparty").'"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 16), 'ISO-8859-1').' - '.$invoicestatic->ref.' - '.$langs->trans("Thirdparty").'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; - print '"'.$journal.'"'; - print "\n"; @@ -911,13 +605,13 @@ - print '"'.$key.'"'.$sep; - print '"'.$date.'"'.$sep; - print '"'.$val["ref"].'"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 32), 'ISO-8859-1').'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '""'.$sep; - print '"'.mb_convert_encoding(dol_trunc($accountingaccount->label, 32), 'ISO-8859-1').'"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 16), 'ISO-8859-1').' - '.dol_trunc($accountingaccount->label, 32).'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; - print '"'.$journal.'"'; - print "\n"; + print '"'.$key.'"'.$sep; + print '"'.$date.'"'.$sep; + print '"'.$val["ref"].'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep; + print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; + print '""'.$sep; + print '"'.utf8_decode(dol_trunc($accountingaccount->label, 32)).'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.dol_trunc($accountingaccount->label, 32).'"'.$sep; + print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; + print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; + print '"'.$journal.'"'; + print "\n"; @@ -931,6 +625,2 @@ - if ($numtax == 1) { - $arrayofvat = $tablocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tablocaltax2; - } + if ($numtax == 1) $arrayofvat = $tablocaltax1; + if ($numtax == 2) $arrayofvat = $tablocaltax2; @@ -943 +633 @@ - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 32), 'ISO-8859-1').'"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 32)).'"'.$sep; @@ -947,2 +637,2 @@ - print '"'.$langs->trans("VAT").' - '.join(', ', $def_tva[$key][$k]).' %"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 16), 'ISO-8859-1').' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '').'"'.$sep; + print '"'.$langs->trans("VAT").' - '.$def_tva[$key].' %"'.$sep; + print '"'.utf8_decode(dol_trunc($companystatic->name, 16)).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : '').'"'.$sep; @@ -956,21 +645,0 @@ - - // Revenue stamp - if (isset($tabrevenuestamp[$key])) { - foreach ($tabrevenuestamp[$key] as $k => $mt) { - //if ($mt) { - print '"'.$key.'"'.$sep; - print '"'.$date.'"'.$sep; - print '"'.$val["ref"].'"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 32), 'ISO-8859-1').'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '"'.length_accountg(html_entity_decode($k)).'"'.$sep; - print '""'.$sep; - print '"'.$langs->trans("RevenueStamp").'"'.$sep; - print '"'.mb_convert_encoding(dol_trunc($companystatic->name, 16), 'ISO-8859-1').' - '.$invoicestatic->ref.' - '.$langs->trans("RevenueStamp").'"'.$sep; - print '"'.($mt < 0 ? price(-$mt) : '').'"'.$sep; - print '"'.($mt >= 0 ? price($mt) : '').'"'.$sep; - print '"'.$journal.'"'; - print "\n"; - //} - } - } @@ -983,5 +652,3 @@ - $title = $langs->trans("GenerationOfAccountingEntries").' - '.$accountingjournalstatic->getNomUrl(0, 2, 1, '', 1); - - llxHeader('', dol_string_nohtmltag($title)); - - $nom = $title; + llxHeader('', $langs->trans("SellsJournal")); + + $nom = $langs->trans("SellsJournal").' | '.$accountingjournalstatic->getNomUrl(0, 1, 1, '', 1); @@ -992,2 +659,2 @@ - $description = $langs->trans("DescJournalOnlyBindedVisible").'
'; - if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) { + $description .= $langs->trans("DescJournalOnlyBindedVisible").'
'; + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) @@ -995 +662 @@ - } else { + else @@ -997 +663,0 @@ - } @@ -1000,2 +666,2 @@ - $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0); - $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); + $period = $form->selectDate($date_start ? $date_start : -1, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end ? $date_end : -1, 'date_end', 0, 0, 0, '', 1, 0); + $period .= ' - '.$langs->trans("JournalizationInLedgerStatus").' '.$form->selectarray('in_bookkeeping', $listofchoices, $in_bookkeeping, 1); @@ -1007,19 +672,0 @@ - if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') != 'blockedonclosed') { - // Test that setup is complete (we are in accounting, so test on entity is always on $conf->entity only, no sharing allowed) - // Fiscal period test - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE entity = ".((int) $conf->entity); - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - if ($obj->nb == 0) { - print '
'.img_warning().' '.$langs->trans("TheFiscalPeriodIsNotDefined"); - $desc = ' : '.$langs->trans("AccountancyAreaDescFiscalPeriod", 4, '{link}'); - $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("FiscalPeriod").'', $desc); - print $desc; - print '
'; - } - } else { - dol_print_error($db); - } - } - @@ -1027,13 +674,8 @@ - $acctCustomerNotConfigured = in_array(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), ['','-1']); - if ($acctCustomerNotConfigured) { - print '
'.img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); - $desc = ' : '.$langs->trans("AccountancyAreaDescMisc", 4, '{link}'); - $desc = str_replace('{link}', ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'', $desc); - print $desc; - print '
'; - } - print '
'; - if (getDolGlobalString('ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL') && $in_bookkeeping == 'notyet') { - print ''; - } - if ($acctCustomerNotConfigured) { + if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') { + print '
'; + print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + } + print '
'; + if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL) && $in_bookkeeping == 'notyet') print ''; + if (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == "") || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') { @@ -1041,6 +683,4 @@ - } else { - if ($in_bookkeeping == 'notyet') { - print ''; - } else { - print ''.$langs->trans("WriteBookKeeping").''; - } + } + else { + if ($in_bookkeeping == 'notyet') print ''; + else print ''.$langs->trans("WriteBookKeeping").''; @@ -1070,0 +711 @@ + $i = 0; @@ -1079,2 +720,2 @@ - print '
"; - print '"; + print '"; + print '"; @@ -1083 +724 @@ - $i = 0; + $r = ''; @@ -1088 +729,2 @@ - foreach ($tabfac as $key => $val) { + foreach ($tabfac as $key => $val) + { @@ -1092 +734 @@ - $companystatic->code_compta_client = $tabcompany[$key]['code_compta']; + $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; @@ -1093,0 +736 @@ + $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; @@ -1105 +748,2 @@ - if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) { + if ($invoicestatic->close_code == Facture::CLOSECODE_REPLACED) + { @@ -1108,3 +752 @@ - if ($alreadydispatched) { - $replacedinvoice = 2; - } + if ($alreadydispatched) $replacedinvoice = 2; @@ -1114 +756,2 @@ - if ($replacedinvoice == 1) { + if ($replacedinvoice == 1) + { @@ -1132 +774,0 @@ - $i++; @@ -1135 +777,2 @@ - if ($errorforinvoice[$key] == 'somelinesarenotbound') { + if ($errorforinvoice[$key] == 'somelinesarenotbound') + { @@ -1152,34 +794,0 @@ - - $i++; - } - - // Warranty - if (getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY') && isset($tabwarranty[$key]) && is_array($tabwarranty[$key])) { - foreach ($tabwarranty[$key] as $k => $mt) { - print ''; - print ""; - print ""; - print ""; - // Account - print "'; - // Subledger account - print "'; - print ""; - print '"; - print '"; - print ""; - } @@ -1189 +798,2 @@ - foreach ($tabttc[$key] as $k => $mt) { + foreach ($tabttc[$key] as $k => $mt) + { @@ -1196,2 +806,3 @@ - $accountoshow = length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER')); - if (($accountoshow == "") || $accountoshow == 'NotDefined') { + $accountoshow = length_accounta($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER); + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { @@ -1199,2 +809,0 @@ - } else { - print $accountoshow; @@ -1201,0 +811 @@ + else print $accountoshow; @@ -1206 +816,2 @@ - if (($accountoshow == "") || $accountoshow == 'NotDefined') { + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { @@ -1208,2 +818,0 @@ - } else { - print $accountoshow; @@ -1210,0 +820 @@ + else print $accountoshow; @@ -1213,2 +823,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -1216,2 +825,0 @@ - - $i++; @@ -1221 +829,2 @@ - foreach ($tabht[$key] as $k => $mt) { + foreach ($tabht[$key] as $k => $mt) + { @@ -1232 +841,2 @@ - if (($accountoshow == "") || $accountoshow == 'NotDefined') { + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { @@ -1234,2 +843,0 @@ - } else { - print $accountoshow; @@ -1236,0 +845 @@ + else print $accountoshow; @@ -1240,7 +848,0 @@ - if (getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) { - if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT')) { - print length_accounta($tabcompany[$key]['code_compta']); - } - } elseif (($accountoshow == "") || $accountoshow == 'NotDefined') { - print '' . $langs->trans("ThirdpartyAccountNotDefined") . ''; - } @@ -1251,2 +853,2 @@ - print '"; - print '"; + print '"; + print '"; @@ -1254,2 +855,0 @@ - - $i++; @@ -1260 +860,2 @@ - foreach ($listoftax as $numtax) { + foreach ($listoftax as $numtax) + { @@ -1262,8 +863,3 @@ - if ($numtax == 1) { - $arrayofvat = $tablocaltax1; - } - if ($numtax == 2) { - $arrayofvat = $tablocaltax2; - } - - // $key is id of invoice + if ($numtax == 1) $arrayofvat = $tablocaltax1; + if ($numtax == 2) $arrayofvat = $tablocaltax2; + @@ -1279,4 +875,3 @@ - if (($accountoshow == "") || $accountoshow == 'NotDefined') { - print ''.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("AccountingJournalType2").')'; - } else { - print $accountoshow; + if (($accountoshow == "") || $accountoshow == 'NotDefined') + { + print ''.$langs->trans("VATAccountNotDefined").' ('.$langs->trans("Sale").')'; @@ -1283,0 +879 @@ + else print $accountoshow; @@ -1288,6 +884 @@ - print ""; - print '"; + print '"; + print '"; @@ -1298,2 +888,0 @@ - - $i++; @@ -1303,30 +891,0 @@ - - // Revenue stamp - if (isset($tabrevenuestamp[$key]) && is_array($tabrevenuestamp[$key])) { - foreach ($tabrevenuestamp[$key] as $k => $mt) { - print ''; - print ""; - print ""; - print ""; - // Account - print "'; - // Subledger account - print "'; - print ""; - print '"; - print '"; - print ""; - } - } - } - - if (!$i) { - print '';
'.$langs->trans("AccountingDebit")."'.$langs->trans("AccountingCredit")."'.$langs->trans("Debit")."'.$langs->trans("Credit")."".dol_escape_htmltag($ref)."".$ref.""; @@ -1240,2 +1072,3 @@ - if (empty($accounttoshow) || $accounttoshow == 'NotDefined') { - $accounttoshow = ''.$langs->trans("BankAccountNotDefined").''; + if (empty($accounttoshow) || $accounttoshow == 'NotDefined') + { + print ''.$langs->trans("BankAccountNotDefined").''; @@ -1243,2 +1076 @@ - print ''; - print $accounttoshow; + else print $accounttoshow; @@ -1246 +1077,0 @@ - @@ -1248 +1079 @@ - print ''; + print ""; @@ -1256,4 +1087,2 @@ - - // Label operation - print ''; - print $reflabel; // This is already html escaped content + print ""; + print $reflabel; @@ -1261 +1089,0 @@ - @@ -1263,2 +1091,2 @@ - print ''.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."".dol_escape_htmltag($ref)."".$ref.""; @@ -1297,24 +1121,12 @@ - if ($tabtype[$key] == 'payment') { - $account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'); - } - if ($tabtype[$key] == 'payment_supplier') { - $account_ledger = getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'); - } - if ($tabtype[$key] == 'payment_expensereport') { - $account_ledger = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'); - } - if ($tabtype[$key] == 'payment_salary') { - $account_ledger = getDolGlobalString('SALARIES_ACCOUNTING_ACCOUNT_PAYMENT'); - } - if ($tabtype[$key] == 'payment_vat') { - $account_ledger = getDolGlobalString('ACCOUNTING_VAT_PAY_ACCOUNT'); - } - if ($tabtype[$key] == 'member') { - $account_ledger = getDolGlobalString('ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT'); - } - if ($tabtype[$key] == 'payment_various') { - $account_ledger = $tabpay[$key]["account_various"]; - } - $accounttoshow = length_accountg($account_ledger); - if (empty($accounttoshow) || $accounttoshow == 'NotDefined') { - if ($tabtype[$key] == 'unknown') { + if ($tabtype[$key] == 'payment') $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; + if ($tabtype[$key] == 'payment_supplier') $account_ledger = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; + if ($tabtype[$key] == 'payment_expensereport') $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + if ($tabtype[$key] == 'payment_salary') $account_ledger = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + if ($tabtype[$key] == 'payment_vat') $account_ledger = $conf->global->ACCOUNTING_VAT_PAY_ACCOUNT; + if ($tabtype[$key] == 'member') $account_ledger = $conf->global->ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT; + if ($tabtype[$key] == 'payment_various') $account_ledger = $tabpay[$key]["account_various"]; + $accounttoshow = length_accounta($account_ledger); + if (empty($accounttoshow) || $accounttoshow == 'NotDefined') + { + if ($tabtype[$key] == 'unknown') + { @@ -1322,4 +1134,3 @@ - if (!getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE') || getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE') == '-1') { - $accounttoshow = ''.$langs->trans('UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').''; - } else { - $accounttoshow = ''.$langs->trans('UnknownAccountForThirdparty', length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_SUSPENSE'))).''; // We will use a waiting account + if (empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) || $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE == '-1') + { + print ''.$langs->trans('UnknownAccountForThirdpartyAndWaitingAccountNotDefinedBlocking').''; @@ -1327 +1138,7 @@ - } else { + else + { + print ''.$langs->trans('UnknownAccountForThirdparty', length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE)).''; // We will use a waiting account + } + } + else + { @@ -1330,19 +1147,7 @@ - if ($tabtype[$key] == 'payment') { - $errorstring = 'MainAccountForCustomersNotDefined'; - } - if ($tabtype[$key] == 'payment_supplier') { - $errorstring = 'MainAccountForSuppliersNotDefined'; - } - if ($tabtype[$key] == 'payment_expensereport') { - $errorstring = 'MainAccountForUsersNotDefined'; - } - if ($tabtype[$key] == 'payment_salary') { - $errorstring = 'MainAccountForUsersNotDefined'; - } - if ($tabtype[$key] == 'payment_vat') { - $errorstring = 'MainAccountForVatPaymentNotDefined'; - } - if ($tabtype[$key] == 'member') { - $errorstring = 'MainAccountForSubscriptionPaymentNotDefined'; - } - $accounttoshow = ''.$langs->trans($errorstring).''; + if ($tabtype[$key] == 'payment') $errorstring = 'MainAccountForCustomersNotDefined'; + if ($tabtype[$key] == 'payment_supplier') $errorstring = 'MainAccountForSuppliersNotDefined'; + if ($tabtype[$key] == 'payment_expensereport') $errorstring = 'MainAccountForUsersNotDefined'; + if ($tabtype[$key] == 'payment_salary') $errorstring = 'MainAccountForUsersNotDefined'; + if ($tabtype[$key] == 'payment_vat') $errorstring = 'MainAccountForVatPaymentNotDefined'; + if ($tabtype[$key] == 'member') $errorstring = 'MainAccountForSubscriptionPaymentNotDefined'; + print ''.$langs->trans($errorstring).''; @@ -1351,2 +1156 @@ - print ''; - print $accounttoshow; // This is a HTML string + else print $accounttoshow; @@ -1356,2 +1160,3 @@ - $accounttoshowsubledger = ''; - if (in_array($tabtype[$key], array('payment', 'payment_supplier', 'payment_expensereport', 'payment_salary', 'payment_various'))) { // Type of payments that uses a subledger + print ""; + if (in_array($tabtype[$key], array('payment', 'payment_supplier', 'payment_expensereport', 'payment_salary', 'payment_various'))) // Type of payment with subledger + { @@ -1359,5 +1164,7 @@ - if ($accounttoshow != $accounttoshowsubledger) { - if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined') { - //var_dump($tabpay[$key]); - //var_dump($tabtype[$key]); - //var_dump($tabbq[$key]); + if ($accounttoshow != $accounttoshowsubledger) + { + if (empty($accounttoshowsubledger) || $accounttoshowsubledger == 'NotDefined') + { + /*var_dump($tabpay[$key]); + var_dump($tabtype[$key]); + var_dump($tabbq[$key]);*/ @@ -1365,2 +1172,3 @@ - if (!empty($tabcompany[$key]['code_compta'])) { - if (in_array($tabtype[$key], array('payment_various', 'payment_salary'))) { + if (!empty($tabcompany[$key]['code_compta'])) + { + if (in_array($tabtype[$key], array('payment_various'))) { @@ -1368 +1176 @@ - $accounttoshowsubledger = ''.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").''; + print ''.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownSubledgerIgnored").''; @@ -1370 +1178 @@ - $accounttoshowsubledger = ''.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key]['code_compta']).''; + print ''.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknown", $tabcompany[$key]['code_compta']).''; @@ -1372,2 +1180,4 @@ - } else { - $accounttoshowsubledger = ''.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").''; + } + else + { + print ''.$langs->trans("ThirdpartyAccountNotDefinedOrThirdPartyUnknownBlocking").''; @@ -1376,2 +1186 @@ - } else { - $accounttoshowsubledger = ''; + else print $accounttoshowsubledger; @@ -1380,2 +1188,0 @@ - print ''; - print $accounttoshowsubledger; // This is a html string @@ -1383 +1189,0 @@ - @@ -1385 +1190,0 @@ - @@ -1387,5 +1192,2 @@ - - print ''.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."".dol_escape_htmltag($reflabel)."".$reflabel."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."
'.$langs->trans("NoRecordFound").'
'.$langs->trans("AccountingDebit")."'.$langs->trans("AccountingCredit")."'.$langs->trans("Debit")."'.$langs->trans("Credit")."
".$date."".$expensereportstatic->getNomUrl(1).""; - print ''.$langs->trans('ErrorInvoiceContainsLinesNotYetBoundedShort', $val['ref']).''; - print '"; - print '"; - print "
'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? -price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."
'.$langs->trans("NoRecordFound").'
'.$langs->trans("AccountingDebit")."'.$langs->trans("AccountingCredit")."'.$langs->trans("Debit")."'.$langs->trans("Credit")."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."
'.$langs->trans("NoRecordFound").'
'.$langs->trans("AccountingDebit")."'.$langs->trans("AccountingCredit")."'.$langs->trans("Debit")."'.$langs->trans("Credit")."
" . $date . "" . $invoicestatic->getNomUrl(1) . ""; - $accountoshow = length_accountg(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY')); - if (($accountoshow == "") || $accountoshow == 'NotDefined') { - print '' . $langs->trans("MainAccountForRetainedWarrantyNotDefined") . ''; - } else { - print $accountoshow; - } - print '"; - $accountoshow = length_accounta($k); - if (($accountoshow == "") || $accountoshow == 'NotDefined') { - print '' . $langs->trans("ThirdpartyAccountNotDefined") . ''; - } else { - print $accountoshow; - } - print '" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Retainedwarranty") . "' . ($mt >= 0 ? price($mt) : '') . "' . ($mt < 0 ? price(-$mt) : '') . "
'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref; - // $def_tva is array[invoiceid][accountancy_code_sell_of_vat_rate_found][vatrate]=vatrate - //var_dump($arrayofvat[$key]); var_dump($key); var_dump($k); - $tmpvatrate = (empty($def_tva[$key][$k]) ? (empty($arrayofvat[$key][$k]) ? '' : $arrayofvat[$key][$k]) : join(', ', $def_tva[$key][$k])); - print ' - '.$langs->trans("Taxes").' '.$tmpvatrate.' %'; - print($numtax ? ' - Localtax '.$numtax : ''); + print "".$companystatic->getNomUrl(0, 'customer', 16).' - '.$invoicestatic->ref.' - '.$langs->trans("VAT").' '.join(', ', $def_tva[$key][$k]).' %'.($numtax ? ' - Localtax '.$numtax : ''); @@ -1295,2 +886,2 @@ - print ''.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."'.($mt < 0 ? price(-$mt) : '')."'.($mt >= 0 ? price($mt) : '')."
" . $date . "" . $invoicestatic->getNomUrl(1) . ""; - $accountoshow = length_accountg($k); - if (($accountoshow == "") || $accountoshow == 'NotDefined') { - print '' . $langs->trans("MainAccountForRevenueStampSaleNotDefined") . ''; - } else { - print $accountoshow; - } - print '"; - print '" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("RevenueStamp") . "' . ($mt < 0 ? price(-$mt) : '') . "' . ($mt >= 0 ? price($mt) : '') . "
'.$langs->trans("NoRecordFound").'