code syntax compta directory

This commit is contained in:
Frédéric FRANCE 2021-02-23 21:09:01 +01:00
parent 2642e1d1b3
commit 61600a9e65
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
130 changed files with 13105 additions and 10799 deletions

View File

@ -25,7 +25,9 @@
*/
if ((array_key_exists('action', $_GET) && $_GET['action'] == 'dl') || (array_key_exists('action', $_POST) && $_POST['action'] == 'dl')) { // To not replace token when downloading file
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1');
}
}
require '../main.inc.php';
@ -70,12 +72,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortfield) $sortfield = "date,item"; // Set here default search field
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) {
$sortfield = "date,item"; // Set here default search field
}
if (!$sortorder) {
$sortorder = "DESC";
}
$arrayfields = array(
@ -111,7 +119,9 @@ if (!empty($conf->multicompany->enabled) && is_object($mc)) {
$entity = '0,'.join(',', array_keys($arrayofentities));
}
}
if (empty($entity)) $entity = $conf->entity;
if (empty($entity)) {
$entity = $conf->entity;
}
$error = 0;
@ -129,26 +139,25 @@ $error = 0;
$filesarray = array();
$result = false;
if (($action == 'searchfiles' || $action == 'dl')) {
if (empty($date_start))
{
if (empty($date_start)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateStart")), null, 'errors');
$error++;
}
if (empty($date_stop))
{
if (empty($date_stop)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
$error++;
}
if (!$error)
{
if (!$error) {
$sql = '';
$wheretail = " '".$db->idate($date_start)."' AND '".$db->idate($date_stop)."'";
// Customer invoices
if (GETPOST('selectinvoices')) {
if (!empty($sql)) $sql .= " UNION ALL";
if (!empty($sql)) {
$sql .= " UNION ALL";
}
$sql .= "SELECT t.rowid as id, t.entity, t.ref, t.paye as paid, t.total as total_ht, t.total_ttc, t.tva as total_vat, t.multicurrency_code as currency, t.fk_soc, t.datef as date, t.date_lim_reglement as date_due, 'Invoice' as item, s.nom as thirdparty_name, s.code_client as thirdparty_code, c.code as country_code, s.tva_intra as vatnum, ".PAY_CREDIT." as sens";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as t LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = t.fk_soc LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = s.fk_pays";
$sql .= " WHERE datef between ".$wheretail;
@ -157,7 +166,9 @@ if (($action == 'searchfiles' || $action == 'dl')) {
}
// Vendor invoices
if (GETPOST('selectsupplierinvoices')) {
if (!empty($sql)) $sql .= " UNION ALL";
if (!empty($sql)) {
$sql .= " UNION ALL";
}
$sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paye as paid, t.total_ht, t.total_ttc, t.total_tva as total_vat, t.multicurrency_code as currency, t.fk_soc, t.datef as date, t.date_lim_reglement as date_due, 'SupplierInvoice' as item, s.nom as thirdparty_name, s.code_fournisseur as thirdparty_code, c.code as country_code, s.tva_intra as vatnum, ".PAY_DEBIT." as sens";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as t LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = t.fk_soc LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = s.fk_pays";
$sql .= " WHERE datef between ".$wheretail;
@ -166,7 +177,9 @@ if (($action == 'searchfiles' || $action == 'dl')) {
}
// Expense reports
if (GETPOST('selectexpensereports')) {
if (!empty($sql)) $sql .= " UNION ALL";
if (!empty($sql)) {
$sql .= " UNION ALL";
}
$sql .= " SELECT t.rowid as id, t.entity, t.ref, t.paid, t.total_ht, t.total_ttc, t.total_tva as total_vat, t.multicurrency_code as currency, t.fk_user_author as fk_soc, t.date_fin as date, t.date_fin as date_due, 'ExpenseReport' as item, CONCAT(CONCAT(u.lastname, ' '), u.firstname) as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, ".PAY_DEBIT." as sens";
$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as t LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = t.fk_user_author LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = u.fk_country";
$sql .= " WHERE date_fin between ".$wheretail;
@ -175,7 +188,9 @@ if (($action == 'searchfiles' || $action == 'dl')) {
}
// Donations
if (GETPOST('selectdonations')) {
if (!empty($sql)) $sql .= " UNION ALL";
if (!empty($sql)) {
$sql .= " UNION ALL";
}
$sql .= " SELECT t.rowid as id, t.entity, t.ref, paid, amount as total_ht, amount as total_ttc, 0 as total_vat, '".$db->escape($conf->currency)."' as currency, 0 as fk_soc, t.datedon as date, t.datedon as date_due, 'Donation' as item, t.societe as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, ".PAY_CREDIT." as sens";
$sql .= " FROM ".MAIN_DB_PREFIX."don as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = t.fk_country";
$sql .= " WHERE datedon between ".$wheretail;
@ -184,7 +199,9 @@ if (($action == 'searchfiles' || $action == 'dl')) {
}
// Payments of salaries
if (GETPOST('selectpaymentsofsalaries')) {
if (!empty($sql)) $sql .= " UNION ALL";
if (!empty($sql)) {
$sql .= " UNION ALL";
}
$sql .= " SELECT t.rowid as id, t.entity, t.label as ref, 1 as paid, amount as total_ht, amount as total_ttc, 0 as total_vat, '".$db->escape($conf->currency)."' as currency, t.fk_user as fk_soc, t.datep as date, t.dateep as date_due, 'SalaryPayment' as item, CONCAT(CONCAT(u.lastname, ' '), u.firstname) as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum, ".PAY_DEBIT." as sens";
$sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = t.fk_user LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = u.fk_country";
$sql .= " WHERE datep between ".$wheretail;
@ -193,7 +210,9 @@ if (($action == 'searchfiles' || $action == 'dl')) {
}
// Social contributions
if (GETPOST('selectsocialcontributions')) {
if (!empty($sql)) $sql .= " UNION ALL";
if (!empty($sql)) {
$sql .= " UNION ALL";
}
$sql .= " SELECT t.rowid as id, t.entity, t.libelle as ref, t.paye as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_vat, '".$db->escape($conf->currency)."' as currency, 0 as fk_soc, t.date_ech as date, t.periode as date_due, 'SocialContributions' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, ".PAY_DEBIT." as sens";
$sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as t";
$sql .= " WHERE t.date_ech between ".$wheretail;
@ -202,7 +221,9 @@ if (($action == 'searchfiles' || $action == 'dl')) {
}
// Various payments
if (GETPOST('selectvariouspayment')) {
if (!empty($sql)) $sql .= " UNION ALL";
if (!empty($sql)) {
$sql .= " UNION ALL";
}
$sql .= " SELECT t.rowid as id, t.entity, t.ref, 1 as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_vat, '".$db->escape($conf->currency)."' as currency, 0 as fk_soc, t.datep as date, t.datep as date_due, 'VariousPayment' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, sens";
$sql .= " FROM ".MAIN_DB_PREFIX."payment_various as t";
$sql .= " WHERE datep between ".$wheretail;
@ -210,7 +231,9 @@ if (($action == 'searchfiles' || $action == 'dl')) {
}
// Loan payments
if (GETPOST('selectloanspayment')) {
if (!empty($sql)) $sql .= " UNION ALL";
if (!empty($sql)) {
$sql .= " UNION ALL";
}
$sql .= " SELECT t.rowid as id, l.entity, l.label as ref, 1 as paid, (t.amount_capital+t.amount_insurance+t.amount_interest) as total_ht, (t.amount_capital+t.amount_insurance+t.amount_interest) as total_ttc, 0 as total_vat, '".$db->escape($conf->currency)."' as currency, 0 as fk_soc, t.datep as date, t.datep as date_due, 'LoanPayment' as item, '' as thirdparty_name, '' as thirdparty_code, '' as country_code, '' as vatnum, ".PAY_DEBIT." as sens";
$sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as t LEFT JOIN ".MAIN_DB_PREFIX."loan as l ON l.rowid = t.fk_loan";
$sql .= " WHERE datep between ".$wheretail;
@ -225,8 +248,7 @@ if (($action == 'searchfiles' || $action == 'dl')) {
$files = array();
$link = '';
if ($resd)
{
if ($resd) {
$numd = $db->num_rows($resd);
$tmpinvoice = new Facture($db);
@ -235,12 +257,10 @@ if (($action == 'searchfiles' || $action == 'dl')) {
$upload_dir = '';
$i = 0;
while ($i < $numd)
{
while ($i < $numd) {
$objd = $db->fetch_object($resd);
switch ($objd->item)
{
switch ($objd->item) {
case "Invoice":
$subdir = '';
$subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref);
@ -306,15 +326,13 @@ if (($action == 'searchfiles' || $action == 'dl')) {
break;
}
if (!empty($upload_dir))
{
if (!empty($upload_dir)) {
$result = true;
$files = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', '', SORT_ASC, 1);
//var_dump($upload_dir);
//var_dump($files);
if (count($files) < 1)
{
if (count($files) < 1) {
$nofile = array();
$nofile['id'] = $objd->id;
$nofile['entity'] = $objd->entity;
@ -335,8 +353,7 @@ if (($action == 'searchfiles' || $action == 'dl')) {
$filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile;
} else {
foreach ($files as $key => $file)
{
foreach ($files as $key => $file) {
$file['id'] = $objd->id;
$file['entity'] = $objd->entity;
$file['date'] = $db->idate($objd->date);
@ -399,17 +416,14 @@ if (($action == 'searchfiles' || $action == 'dl')) {
*/
$dirfortmpfile = ($conf->accounting->dir_temp ? $conf->accounting->dir_temp : $conf->comptabilite->dir_temp);
if (empty($dirfortmpfile))
{
if (empty($dirfortmpfile)) {
setEventMessages($langs->trans("ErrorNoAccountingModuleEnabled"), null, 'errors');
$error++;
}
if ($result && $action == "dl" && !$error)
{
if (!extension_loaded('zip'))
{
if ($result && $action == "dl" && !$error) {
if (!extension_loaded('zip')) {
setEventMessages('PHPZIPExtentionNotLoaded', null, 'errors');
exit;
}
@ -417,8 +431,7 @@ if ($result && $action == "dl" && !$error)
dol_mkdir($dirfortmpfile);
$log = $langs->transnoentitiesnoconv("Type");
if (!empty($conf->multicompany->enabled) && is_object($mc))
{
if (!empty($conf->multicompany->enabled) && is_object($mc)) {
$log .= ','.$langs->transnoentitiesnoconv("Entity");
}
$log .= ','.$langs->transnoentitiesnoconv("Date");
@ -441,10 +454,8 @@ if ($result && $action == "dl" && !$error)
$zip = new ZipArchive;
$res = $zip->open($zipname, ZipArchive::OVERWRITE | ZipArchive::CREATE);
if ($res)
{
foreach ($filesarray as $key => $file)
{
if ($res) {
foreach ($filesarray as $key => $file) {
if (!empty($file['files'])) {
foreach ($file['files'] as $filecursor) {
if (file_exists($filecursor["fullname"])) {
@ -454,8 +465,7 @@ if ($result && $action == "dl" && !$error)
}
$log .= '"'.$langs->trans($file['item']).'"';
if (!empty($conf->multicompany->enabled) && is_object($mc))
{
if (!empty($conf->multicompany->enabled) && is_object($mc)) {
$log .= ',"'.(empty($arrayofentities[$file['entity']]) ? $file['entity'] : $arrayofentities[$file['entity']]).'"';
}
$log .= ','.dol_print_date($file['date'], 'dayrfc');
@ -532,8 +542,7 @@ print $langs->trans("ReportPeriod").': '.$form->selectDate($date_start, 'date_st
print ' - '.$form->selectDate($date_stop, 'date_stop', 0, 0, 0, "", 1, 1, 0)."\n";
// Export is for current company only
if (!empty($conf->multicompany->enabled) && is_object($mc))
{
if (!empty($conf->multicompany->enabled) && is_object($mc)) {
$mc->getInfo($conf->entity);
print '<span class="marginleftonly marginrightonly'.(empty($conf->global->MULTICOMPANY_ALLOW_EXPORT_ACCOUNTING_DOC_FOR_ALL_ENTITIES) ? ' opacitymedium' : '').'">('.$langs->trans("Entity").' : ';
print "<td>";
@ -559,7 +568,9 @@ $listofchoices = array(
'selectloanspayment'=>array('label'=>'PaymentLoan', 'enabled' => !empty($conf->loan->enabled)),
);
foreach ($listofchoices as $choice => $val) {
if (empty($val['enabled'])) continue; // list not qualified
if (empty($val['enabled'])) {
continue; // list not qualified
}
$checked = (((!GETPOSTISSET('search') && $action != 'searchfiles') || GETPOST($choice)) ? ' checked="checked"' : '');
print '<div class="paddingleft inline-block marginrightonly"><input type="checkbox" id="'.$choice.'" name="'.$choice.'" value="1"'.$checked.'> <label for="'.$choice.'">'.$langs->trans($val['label']).'</label></div>';
}
@ -570,8 +581,7 @@ print '</form>'."\n";
print dol_get_fiche_end();
if (!empty($date_start) && !empty($date_stop))
{
if (!empty($date_start) && !empty($date_stop)) {
$param = 'action=searchfiles';
$param .= '&date_startday='.GETPOST('date_startday', 'int');
$param .= '&date_startmonth='.GETPOST('date_startmonth', 'int');
@ -614,14 +624,14 @@ if (!empty($date_start) && !empty($date_stop))
print '<td class="center">'.$langs->trans("Code").'</td>';
print '<td class="center">'.$langs->trans("Country").'</td>';
print '<td class="center">'.$langs->trans("VATIntra").'</td>';
if (!empty($conf->multicurrency->enabled)) print '<td class="center">'.$langs->trans("Currency").'</td>';
if (!empty($conf->multicurrency->enabled)) {
print '<td class="center">'.$langs->trans("Currency").'</td>';
}
print '</tr>';
if ($result)
{
if ($result) {
$TData = dol_sort_array($filesarray, $sortfield, $sortorder);
if (empty($TData))
{
if (empty($TData)) {
print '<tr class="oddeven"><td colspan="7">'.$langs->trans("NoItem").'</td>';
if (!empty($conf->multicurrency->enabled)) {
print '<td></td>';
@ -638,8 +648,7 @@ if (!empty($date_start) && !empty($date_stop))
$totalVAT_credit = 0;
// Display array
foreach ($TData as $data)
{
foreach ($TData as $data) {
$html_class = '';
//if (!empty($data['fk_facture'])) $html_class = 'facid-'.$data['fk_facture'];
//elseif (!empty($data['fk_paiement'])) $html_class = 'payid-'.$data['fk_paiement'];
@ -708,9 +717,8 @@ if (!empty($date_start) && !empty($date_stop))
// File link
print '<td>';
if (!empty($data['files']))
{
foreach ($data['files'] as $id=>$filecursor) {
if (!empty($data['files'])) {
foreach ($data['files'] as $id => $filecursor) {
print '<a href='.DOL_URL_ROOT.'/'.$filecursor['link'].' target="_blank">'.($filecursor['name'] ? $filecursor['name'] : $filecursor['ref']).'</a>&nbsp;'.$formfile->showPreview($filecursor, $filecursor['modulepart'], $filecursor['subdir'].'/'.$filecursor['name']).'<br>';
}
}

View File

@ -20,11 +20,21 @@
* \brief File to return Ajax response on payment breakdown process
*/
if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1');
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
if (!defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', '1');
}
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1');
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1'); // If there is no menu to show
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
}
require '../main.inc.php';
@ -46,18 +56,20 @@ $currentInvId = $_POST['imgClicked']; // from DOM elements : imgId (equals invoi
$amountPayment = $amountPayment != '' ? (is_numeric(price2num($amountPayment)) ? price2num($amountPayment) : '') : ''; // keep void if not a valid entry
// Clean checkamounts
foreach ($amounts as $key => $value)
{
foreach ($amounts as $key => $value) {
$value = price2num($value);
$amounts[$key] = $value;
if (empty($value)) unset($amounts[$key]);
if (empty($value)) {
unset($amounts[$key]);
}
}
// Clean remains
foreach ($remains as $key => $value)
{
foreach ($remains as $key => $value) {
$value = price2num($value);
$remains[$key] = (($invoice_type) == 2 ?-1 : 1) * $value;
if (empty($value)) unset($remains[$key]);
if (empty($value)) {
unset($remains[$key]);
}
}
// Treatment
@ -65,19 +77,16 @@ $result = ($amountPayment != '') ? ($amountPayment - array_sum($amounts)) : arra
$toJsonArray = array();
$totalRemaining = price2num(array_sum($remains));
$toJsonArray['label'] = $amountPayment == '' ? '' : $langs->transnoentities('RemainingAmountPayment');
if ($currentInvId) // Here to breakdown
{
if ($currentInvId) { // Here to breakdown
// Get the current amount (from form) and the corresponding remainToPay (from invoice)
$currentAmount = $amounts['amount_'.$currentInvId];
$currentRemain = $remains['remain_'.$currentInvId];
// If amountPayment isn't filled, breakdown invoice amount, else breakdown from amountPayment
if ($amountPayment == '')
{
if ($amountPayment == '') {
// Check if current amount exists in amounts
$amountExists = array_key_exists('amount_'.$currentInvId, $amounts);
if ($amountExists)
{
if ($amountExists) {
$remainAmount = $currentRemain - $currentAmount; // To keep value between curRemain and curAmount
$result += $remainAmount; // result must be deduced by
$currentAmount += $remainAmount; // curAmount put to curRemain
@ -90,8 +99,7 @@ if ($currentInvId) // Here to breakdown
$result += price2num($currentAmount);
$currentAmount = 0;
if ($result >= 0) // then we need to calculate the amount to breakdown
{
if ($result >= 0) { // then we need to calculate the amount to breakdown
$amountToBreakdown = ($result - $currentRemain >= 0 ?
$currentRemain : // Remain can be fully paid
$currentRemain + ($result - $currentRemain)); // Remain can only partially be paid

View File

@ -47,26 +47,30 @@ if ($user->socid) {
$action = '';
$socid = $user->socid;
}
if ($user->socid)
if ($user->socid) {
$socid = $user->socid;
}
// Get parameters
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; }
if (empty($page) || $page == -1) {
$page = 0;
}
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder)
if (!$sortorder) {
$sortorder = "ASC";
if (!$sortfield)
}
if (!$sortfield) {
$sortfield = "name";
}
$object = new Account($db);
if ($id > 0 || !empty($ref))
{
if ($id > 0 || !empty($ref)) {
$result = $object->fetch($id, $ref);
$account = $object->id; // Force the search field on id of account
}
@ -75,8 +79,7 @@ $result = restrictedArea($user, 'banque', $object->id, 'bank_account', '', '');
// Define number of receipt to show (current, previous or next one ?)
$found = false;
if ($_GET["rel"] == 'prev')
{
if ($_GET["rel"] == 'prev') {
// Recherche valeur pour num = numero releve precedent
$sql = "SELECT DISTINCT(b.num_releve) as num";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
@ -86,18 +89,15 @@ if ($_GET["rel"] == 'prev')
dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$numrows = $db->num_rows($resql);
if ($numrows > 0)
{
if ($numrows > 0) {
$obj = $db->fetch_object($resql);
$numref = $obj->num;
$found = true;
}
}
} elseif ($_GET["rel"] == 'next')
{
} elseif ($_GET["rel"] == 'next') {
// Recherche valeur pour num = numero releve precedent
$sql = "SELECT DISTINCT(b.num_releve) as num";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
@ -107,11 +107,9 @@ if ($_GET["rel"] == 'prev')
dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$numrows = $db->num_rows($resql);
if ($numrows > 0)
{
if ($numrows > 0) {
$obj = $db->fetch_object($resql);
$numref = $obj->num;
$found = true;
@ -127,8 +125,7 @@ if ($_GET["rel"] == 'prev')
* Actions
*/
if (!empty($numref))
{
if (!empty($numref)) {
$object->fetch_thirdparty();
$upload_dir = $conf->bank->dir_output."/".$id."/statement/".dol_sanitizeFileName($numref);
}

View File

@ -41,13 +41,14 @@ $ref = GETPOST('ref');
// Security check
$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', $fieldvalue, 'bank_account&bank_account', '', '', $fieldtype);
$year_start = GETPOST('year_start');
$year_current = strftime("%Y", time());
if (!$year_start)
{
if (!$year_start) {
$year_start = $year_current - 2;
$year_end = $year_current;
} else {
@ -68,13 +69,11 @@ $form = new Form($db);
// Get account informations
$object = new Account($db);
if ($id > 0 && !preg_match('/,/', $id)) // if for a particular account and not a list
{
if ($id > 0 && !preg_match('/,/', $id)) { // if for a particular account and not a list
$result = $object->fetch($id);
$id = $object->id;
}
if (!empty($ref))
{
if (!empty($ref)) {
$result = $object->fetch(0, $ref);
$id = $object->id;
}
@ -90,17 +89,16 @@ $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= " WHERE b.fk_account = ba.rowid";
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
$sql .= " AND b.amount >= 0";
if (!empty($id))
if (!empty($id)) {
$sql .= " AND b.fk_account IN (".$db->sanitize($db->escape($id)).")";
}
$sql .= " GROUP BY dm";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$encaiss[$row[1]] = $row[0];
$i++;
@ -116,17 +114,16 @@ $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= " WHERE b.fk_account = ba.rowid";
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
$sql .= " AND b.amount <= 0";
if (!empty($id))
if (!empty($id)) {
$sql .= " AND b.fk_account IN (".$db->sanitize($db->escape($id)).")";
}
$sql .= " GROUP BY dm";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$decaiss[$row[1]] = -$row[0];
$i++;
@ -146,20 +143,19 @@ $link = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?account=".$object->id.
$linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
if (!empty($id))
{
if (!preg_match('/,/', $id))
{
if (!empty($id)) {
if (!preg_match('/,/', $id)) {
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
} else {
$bankaccount = new Account($db);
$listid = explode(',', $id);
foreach ($listid as $key => $aId)
{
foreach ($listid as $key => $aId) {
$bankaccount->fetch($aId);
$bankaccount->label = $bankaccount->ref;
print $bankaccount->getNomUrl(1);
if ($key < (count($listid) - 1)) print ', ';
if ($key < (count($listid) - 1)) {
print ', ';
}
}
}
} else {
@ -176,39 +172,33 @@ print '<div class="div-table-responsive">'; // You can use div-table-responsive-
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
for ($annee = $year_start; $annee <= $year_end; $annee++)
{
for ($annee = $year_start; $annee <= $year_end; $annee++) {
print '<td align="center" width="20%" colspan="2" class="liste_titre borderrightlight">'.$annee.'</td>';
}
print '</tr>';
print '<tr class="liste_titre">';
print '<td class="liste_titre">&nbsp;</td>';
for ($annee = $year_start; $annee <= $year_end; $annee++)
{
for ($annee = $year_start; $annee <= $year_end; $annee++) {
print '<td class="liste_titre" align="center">'.$langs->trans("Debit").'</td><td class="liste_titre" align="center">'.$langs->trans("Credit").'</td>';
}
print '</tr>';
for ($mois = 1; $mois < 13; $mois++)
{
for ($mois = 1; $mois < 13; $mois++) {
print '<tr class="oddeven">';
print "<td>".dol_print_date(dol_mktime(1, 1, 1, $mois, 1, 2000), "%B")."</td>";
for ($annee = $year_start; $annee <= $year_end; $annee++)
{
for ($annee = $year_start; $annee <= $year_end; $annee++) {
$case = sprintf("%04s-%02s", $annee, $mois);
print '<td class="right" width="10%">&nbsp;';
if ($decaiss[$case] > 0)
{
if ($decaiss[$case] > 0) {
print price($decaiss[$case]);
$totsorties[$annee] += $decaiss[$case];
}
print "</td>";
print '<td class="right borderrightlight" width="10%">&nbsp;';
if ($encaiss[$case] > 0)
{
if ($encaiss[$case] > 0) {
print price($encaiss[$case]);
$totentrees[$annee] += $encaiss[$case];
}
@ -219,8 +209,7 @@ for ($mois = 1; $mois < 13; $mois++)
// Total debit-credit
print '<tr class="liste_total"><td><b>'.$langs->trans("Total")."</b></td>";
for ($annee = $year_start; $annee <= $year_end; $annee++)
{
for ($annee = $year_start; $annee <= $year_end; $annee++) {
print '<td class="right nowraponall"><b>'.price($totsorties[$annee]).'</b></td><td class="right nowraponall"><b>'.price($totentrees[$annee]).'</b></td>';
}
print "</tr>\n";
@ -239,14 +228,16 @@ $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= " WHERE b.fk_account = ba.rowid";
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
if (!empty($id))
if (!empty($id)) {
$sql .= " AND b.fk_account IN (".$db->sanitize($db->escape($id)).")";
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj) $balance = $obj->total;
if ($obj) {
$balance = $obj->total;
}
} else {
dol_print_error($db);
}
@ -264,8 +255,7 @@ print "</table>";
$year = $year_end;
$result = dol_mkdir($conf->bank->dir_temp);
if ($result < 0)
{
if ($result < 0) {
$langs->load("errors");
$error++;
setEventMessages($langs->trans("ErrorFailedToCreateDir"), null, 'errors');
@ -276,11 +266,12 @@ if ($result < 0)
$sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= " WHERE b.fk_account = ba.rowid";
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
if ($id && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$id.")";
if ($id && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$id.")";
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$obj = $db->fetch_object($resql);
$min = $db->jdate($obj->min);
@ -297,8 +288,7 @@ if ($result < 0)
$tblyear[1] = array();
$tblyear[2] = array();
for ($annee = 0; $annee < 3; $annee++)
{
for ($annee = 0; $annee < 3; $annee++) {
$sql = "SELECT date_format(b.datev,'%m')";
$sql .= ", SUM(b.amount)";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
@ -308,16 +298,16 @@ if ($result < 0)
$sql .= " AND b.datev >= '".($year - $annee)."-01-01 00:00:00'";
$sql .= " AND b.datev <= '".($year - $annee)."-12-31 23:59:59'";
$sql .= " AND b.amount > 0";
if ($id && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$id.")";
if ($id && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$id.")";
}
$sql .= " GROUP BY date_format(b.datev,'%m');";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$tblyear[$annee][$row[0]] = $row[1];
$i++;
@ -333,8 +323,7 @@ if ($result < 0)
$data_year_1 = array();
$data_year_2 = array();
for ($i = 0; $i < 12; $i++)
{
for ($i = 0; $i < 12; $i++) {
$data_year_0[$i] = isset($tblyear[0][substr("0".($i + 1), -2)]) ? $tblyear[0][substr("0".($i + 1), -2)] : 0;
$data_year_1[$i] = isset($tblyear[1][substr("0".($i + 1), -2)]) ? $tblyear[1][substr("0".($i + 1), -2)] : 0;
$data_year_2[$i] = isset($tblyear[2][substr("0".($i + 1), -2)]) ? $tblyear[2][substr("0".($i + 1), -2)] : 0;
@ -347,8 +336,7 @@ if ($result < 0)
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/credmovement".$id."-".$year.".png";
$title = $langs->transnoentities("Credit").' - '.$langs->transnoentities("Year").': '.($year - 2).' - '.($year - 1)." - ".$year;
$graph_datas = array();
for ($i = 0; $i < 12; $i++)
{
for ($i = 0; $i < 12; $i++) {
$graph_datas[$i] = array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]);
}
@ -382,8 +370,7 @@ if ($result < 0)
$tblyear[1] = array();
$tblyear[2] = array();
for ($annee = 0; $annee < 3; $annee++)
{
for ($annee = 0; $annee < 3; $annee++) {
$sql = "SELECT date_format(b.datev,'%m')";
$sql .= ", SUM(b.amount)";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
@ -393,16 +380,16 @@ if ($result < 0)
$sql .= " AND b.datev >= '".($year - $annee)."-01-01 00:00:00'";
$sql .= " AND b.datev <= '".($year - $annee)."-12-31 23:59:59'";
$sql .= " AND b.amount < 0";
if ($id && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$id.")";
if ($id && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$id.")";
}
$sql .= " GROUP BY date_format(b.datev,'%m');";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$tblyear[$annee][$row[0]] = abs($row[1]);
$i++;
@ -418,8 +405,7 @@ if ($result < 0)
$data_year_1 = array();
$data_year_2 = array();
for ($i = 0; $i < 12; $i++)
{
for ($i = 0; $i < 12; $i++) {
$data_year_0[$i] = isset($tblyear[0][substr("0".($i + 1), -2)]) ? $tblyear[0][substr("0".($i + 1), -2)] : 0;
$data_year_1[$i] = isset($tblyear[1][substr("0".($i + 1), -2)]) ? $tblyear[1][substr("0".($i + 1), -2)] : 0;
$data_year_2[$i] = isset($tblyear[2][substr("0".($i + 1), -2)]) ? $tblyear[2][substr("0".($i + 1), -2)] : 0;
@ -431,8 +417,7 @@ if ($result < 0)
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/debmovement".$id."-".$year.".png";
$title = $langs->transnoentities("Debit").' - '.$langs->transnoentities("Year").': '.($year - 2).' - '.($year - 1)." - ".$year;
$graph_datas = array();
for ($i = 0; $i < 12; $i++)
{
for ($i = 0; $i < 12; $i++) {
$graph_datas[$i] = array($labels[$i], $data_year_0[$i], $data_year_1[$i], $data_year_2[$i]);
}

File diff suppressed because it is too large Load Diff

View File

@ -28,8 +28,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
// Load translation files required by the page
$langs->loadLangs(array('banks', 'categories'));
if (!$user->rights->banque->lire)
accessforbidden();
if (!$user->rights->banque->lire) {
accessforbidden();
}
/**
@ -45,8 +46,7 @@ function valeur($sql)
$valeur = 0;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
$valeur = $obj->amount;
$db->free($resql);

View File

@ -31,7 +31,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->loadLangs(array('banks', 'categories'));
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque');
@ -65,13 +67,11 @@ $sql .= " GROUP BY c.label, c.rowid";
$sql .= " ORDER BY c.label";
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0; $total = 0; $totalnb = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $db->fetch_object($result);
print '<tr class="oddeven">';

View File

@ -35,10 +35,18 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbank.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
if (!empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
if (!empty($conf->categorie->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
}
if (!empty($conf->accounting->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
}
if (!empty($conf->accounting->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
}
if (!empty($conf->accounting->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
}
// Load translation files required by the page
$langs->loadLangs(array("banks", "bills", "categories", "companies", "compta"));
@ -65,10 +73,11 @@ $hookmanager->initHooks(array('bankcard', 'globalcard'));
* Actions
*/
if ($cancel) $action = '';
if ($cancel) {
$action = '';
}
if ($action == 'add')
{
if ($action == 'add') {
$error = 0;
$db->begin();
@ -99,14 +108,17 @@ if ($action == 'add')
$object->ics_transfer = trim(GETPOST("ics_transfer", 'alpha'));
$account_number = GETPOST('account_number', 'alphanohtml');
if (empty($account_number) || $account_number == '-1')
{
if (empty($account_number) || $account_number == '-1') {
$object->account_number = '';
} else {
$object->account_number = $account_number;
}
$fk_accountancy_journal = GETPOST('fk_accountancy_journal', 'int');
if ($fk_accountancy_journal <= 0) { $object->fk_accountancy_journal = ''; } else { $object->fk_accountancy_journal = $fk_accountancy_journal; }
if ($fk_accountancy_journal <= 0) {
$object->fk_accountancy_journal = '';
} else {
$object->fk_accountancy_journal = $fk_accountancy_journal;
}
$object->solde = $_POST["solde"];
$object->date_solde = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST('reday', 'int'), GETPOST("reyear", 'int'));
@ -122,20 +134,17 @@ if ($action == 'add')
$object->fk_user_author = $user->id;
if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number))
{
if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number)) {
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountancyCode")), null, 'errors');
$action = 'create'; // Force chargement page en mode creation
$error++;
}
if (empty($object->ref))
{
if (empty($object->ref)) {
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
$action = 'create'; // Force chargement page en mode creation
$error++;
}
if (empty($object->label))
{
if (empty($object->label)) {
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("LabelBankCashAccount")), null, 'errors');
$action = 'create'; // Force chargement page en mode creation
$error++;
@ -144,11 +153,9 @@ if ($action == 'add')
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object);
if (!$error)
{
if (!$error) {
$id = $object->create($user);
if ($id > 0)
{
if ($id > 0) {
// Category association
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
@ -164,16 +171,14 @@ if ($action == 'add')
}
}
if (!$error)
{
if (!$error) {
$db->commit();
} else {
$db->rollback();
}
}
if ($action == 'update')
{
if ($action == 'update') {
$error = 0;
// Update account
@ -203,14 +208,17 @@ if ($action == 'update')
$object->ics_transfer = trim(GETPOST("ics_transfer", 'alpha'));
$account_number = GETPOST('account_number', 'alpha');
if (empty($account_number) || $account_number == '-1')
{
if (empty($account_number) || $account_number == '-1') {
$object->account_number = '';
} else {
$object->account_number = $account_number;
}
$fk_accountancy_journal = GETPOST('fk_accountancy_journal', 'int');
if ($fk_accountancy_journal <= 0) { $object->fk_accountancy_journal = ''; } else { $object->fk_accountancy_journal = $fk_accountancy_journal; }
if ($fk_accountancy_journal <= 0) {
$object->fk_accountancy_journal = '';
} else {
$object->fk_accountancy_journal = $fk_accountancy_journal;
}
$object->currency_code = trim($_POST["account_currency_code"]);
@ -221,20 +229,17 @@ if ($action == 'update')
$object->min_desired = GETPOST("account_min_desired", 'int');
$object->comment = trim(GETPOST("account_comment", 'restricthtml'));
if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number))
{
if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number)) {
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountancyCode")), null, 'errors');
$action = 'edit'; // Force chargement page en mode creation
$error++;
}
if (empty($object->ref))
{
if (empty($object->ref)) {
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
$action = 'edit'; // Force chargement page en mode creation
$error++;
}
if (empty($object->label))
{
if (empty($object->label)) {
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("LabelBankCashAccount")), null, 'errors');
$action = 'edit'; // Force chargement page en mode creation
$error++;
@ -242,17 +247,14 @@ if ($action == 'update')
$db->begin();
if (!$error)
{
if (!$error) {
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost(null, $object);
}
if (!$error)
{
if (!$error) {
$result = $object->update($user);
if ($result >= 0)
{
if ($result >= 0) {
// Category association
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
@ -265,23 +267,20 @@ if ($action == 'update')
}
}
if (!$error)
{
if (!$error) {
$db->commit();
} else {
$db->rollback();
}
}
if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer)
{
if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer) {
// Delete
$object = new Account($db);
$object->fetch(GETPOST("id", "int"));
$result = $object->delete($user);
if ($result > 0)
{
if ($result > 0) {
setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
header("Location: ".DOL_URL_ROOT."/compta/bank/list.php");
exit;
@ -299,7 +298,9 @@ if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->
$form = new Form($db);
$formbank = new FormBank($db);
$formcompany = new FormCompany($db);
if (!empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
if (!empty($conf->accounting->enabled)) {
$formaccounting = new FormAccounting($db);
}
$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
@ -310,14 +311,12 @@ llxHeader("", $title, $helpurl);
// Creation
if ($action == 'create')
{
if ($action == 'create') {
$object = new Account($db);
print load_fiche_titre($langs->trans("NewFinancialAccount"), '', 'bank_account');
if ($conf->use_javascript_ajax)
{
if ($conf->use_javascript_ajax) {
print "\n".'<script type="text/javascript" language="javascript">';
print 'jQuery(document).ready(function () {
jQuery("#selecttype").change(function() {
@ -359,7 +358,9 @@ if ($action == 'create')
print '<tr><td class="fieldrequired">'.$langs->trans("Currency").'</td>';
print '<td>';
$selectedcode = $object->currency_code;
if (!$selectedcode) $selectedcode = $conf->currency;
if (!$selectedcode) {
$selectedcode = $conf->currency;
}
print $form->selectCurrency((GETPOSTISSET("account_currency_code") ? GETPOST("account_currency_code") : $selectedcode), 'account_currency_code');
//print $langs->trans("Currency".$conf->currency);
//print '<input type="hidden" name="account_currency_code" value="'.$conf->currency.'">';
@ -375,19 +376,22 @@ if ($action == 'create')
$selectedcode = '';
if (GETPOSTISSET("account_country_id")) {
$selectedcode = GETPOST("account_country_id") ? GETPOST("account_country_id") : $object->country_code;
} elseif (empty($selectedcode)) $selectedcode = $mysoc->country_code;
} elseif (empty($selectedcode)) {
$selectedcode = $mysoc->country_code;
}
$object->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
print '<tr><td class="fieldrequired">'.$langs->trans("BankAccountCountry").'</td>';
print '<td>';
print $form->select_country($selectedcode, 'account_country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
if ($user->admin) {
print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
}
print '</td></tr>';
// State
print '<tr><td>'.$langs->trans('State').'</td><td>';
if ($selectedcode)
{
if ($selectedcode) {
$formcompany->select_departement(GETPOSTISSET("account_state_id") ? GETPOST("account_state_id") : '', $selectedcode, 'account_state_id');
} else {
print $countrynotdefined;
@ -399,16 +403,14 @@ if ($action == 'create')
print '<td><input class="minwidth300" type="text" class="flat" name="url" value="'.GETPOST("url").'"></td></tr>';
// Tags-Categories
if ($conf->categorie->enabled)
{
if ($conf->categorie->enabled) {
print '<tr><td>'.$langs->trans("Categories").'</td><td>';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1);
$arrayselected = array();
$c = new Categorie($db);
$cats = $c->containing($object->id, Categorie::TYPE_ACCOUNT);
if (is_array($cats))
{
if (is_array($cats)) {
foreach ($cats as $cat) {
$arrayselected[] = $cat->id;
}
@ -430,8 +432,7 @@ if ($action == 'create')
$parameters = array();
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (empty($reshook))
{
if (empty($reshook)) {
print $object->showOptionals($extrafields, 'edit', $parameters);
}
@ -459,8 +460,7 @@ if ($action == 'create')
print '</table>';
print '<br>';
if ($_POST["type"] == Account::TYPE_SAVINGS || $_POST["type"] == Account::TYPE_CURRENT)
{
if ($_POST["type"] == Account::TYPE_SAVINGS || $_POST["type"] == Account::TYPE_CURRENT) {
print '<table class="border centpercent">';
// If bank account
@ -495,7 +495,9 @@ if ($action == 'create')
}
$ibankey = FormBank::getIBANLabel($object);
$bickey = "BICNumber";
if ($object->getCountryCode() == 'IN') $bickey = "SWIFT";
if ($object->getCountryCode() == 'IN') {
$bickey = "SWIFT";
}
// IBAN
print '<tr><td>'.$langs->trans($ibankey).'</td>';
@ -525,10 +527,11 @@ if ($action == 'create')
print '<table class="border centpercent">';
// Accountancy code
$fieldrequired = '';
if (!empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED)) $fieldrequired = 'fieldrequired ';
if (!empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED)) {
$fieldrequired = 'fieldrequired ';
}
if (!empty($conf->accounting->enabled))
{
if (!empty($conf->accounting->enabled)) {
print '<tr><td class="'.$fieldrequired.'titlefieldcreate">'.$langs->trans("AccountancyCode").'</td>';
print '<td>';
print $formaccounting->select_account($object->account_number, 'account_number', 1, '', 1, 1);
@ -539,8 +542,7 @@ if ($action == 'create')
}
// Accountancy journal
if (!empty($conf->accounting->enabled))
{
if (!empty($conf->accounting->enabled)) {
print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
print '<td>';
print $formaccounting->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, 0, 0);
@ -567,12 +569,10 @@ if ($action == 'create')
if (($_GET["id"] || $_GET["ref"]) && $action != 'edit') {
$object = new Account($db);
if ($_GET["id"])
{
if ($_GET["id"]) {
$object->fetch($_GET["id"]);
}
if ($_GET["ref"])
{
if ($_GET["ref"]) {
$object->fetch(0, $_GET["ref"]);
$_GET["id"] = $object->id;
}
@ -584,8 +584,7 @@ if ($action == 'create')
$formconfirm = '';
// Confirmation to delete
if ($action == 'delete')
{
if ($action == 'delete') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("DeleteAccount"), $langs->trans("ConfirmDeleteAccount"), "confirm_delete");
}
@ -612,7 +611,9 @@ if ($action == 'create')
print '<tr><td>'.$langs->trans("Currency").'</td>';
print '<td>';
$selectedcode = $object->currency_code;
if (!$selectedcode) $selectedcode = $conf->currency;
if (!$selectedcode) {
$selectedcode = $conf->currency;
}
print $langs->trans("Currency".$selectedcode);
print '</td></tr>';
@ -620,9 +621,13 @@ if ($action == 'create')
print '<tr><td>'.$langs->trans("Conciliable").'</td>';
print '<td>';
$conciliate = $object->canBeConciliated();
if ($conciliate == -2) print $langs->trans("No").' <span class="opacitymedium">('.$langs->trans("CashAccount").')</span>';
elseif ($conciliate == -3) print $langs->trans("No").' <span class="opacitymedium">('.$langs->trans("Closed").')</span>';
else print ($object->rappro == 1 ? $langs->trans("Yes") : ($langs->trans("No").' <span class="opacitymedium">('.$langs->trans("ConciliationDisabled").')</span>'));
if ($conciliate == -2) {
print $langs->trans("No").' <span class="opacitymedium">('.$langs->trans("CashAccount").')</span>';
} elseif ($conciliate == -3) {
print $langs->trans("No").' <span class="opacitymedium">('.$langs->trans("Closed").')</span>';
} else {
print ($object->rappro == 1 ? $langs->trans("Yes") : ($langs->trans("No").' <span class="opacitymedium">('.$langs->trans("ConciliationDisabled").')</span>'));
}
print '</td></tr>';
print '<tr><td>'.$langs->trans("BalanceMinimalAllowed").'</td>';
@ -645,8 +650,7 @@ if ($action == 'create')
print '</td></tr>';
// Accountancy journal
if (!empty($conf->accounting->enabled))
{
if (!empty($conf->accounting->enabled)) {
print '<tr><td>'.$langs->trans("AccountancyJournal").'</td>';
print '<td>';
@ -684,8 +688,7 @@ if ($action == 'create')
print '</table>';
if ($object->type == Account::TYPE_SAVINGS || $object->type == Account::TYPE_CURRENT)
{
if ($object->type == Account::TYPE_SAVINGS || $object->type == Account::TYPE_CURRENT) {
print '<div class="underbanner clearboth"></div>';
print '<table class="border tableforfield centpercent">';
@ -712,7 +715,9 @@ if ($action == 'create')
$ibankey = FormBank::getIBANLabel($object);
$bickey = "BICNumber";
if ($object->getCountryCode() == 'IN') $bickey = "SWIFT";
if ($object->getCountryCode() == 'IN') {
$bickey = "SWIFT";
}
print '<tr><td>'.$langs->trans($ibankey).'</td>';
print '<td>'.$object->iban.'&nbsp;';
@ -736,13 +741,13 @@ if ($action == 'create')
}
print '</td></tr>';
if ($conf->prelevement->enabled){
if ($conf->prelevement->enabled) {
print '<tr><td>'.$langs->trans("ICS").'</td>';
print '<td>'.$object->ics.'</td>';
print '</tr>';
}
if ($conf->paymentbybanktransfer->enabled){
if ($conf->paymentbybanktransfer->enabled) {
print '<tr><td>'.$langs->trans("ICSTransfer").'</td>';
print '<td>'.$object->ics_transfer.'</td>';
print '</tr>';
@ -776,14 +781,12 @@ if ($action == 'create')
*/
print '<div class="tabsAction">';
if ($user->rights->banque->configurer)
{
if ($user->rights->banque->configurer) {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Modify").'</a>';
}
$canbedeleted = $object->can_be_deleted(); // Renvoi vrai si compte sans mouvements
if ($user->rights->banque->configurer && $canbedeleted)
{
if ($user->rights->banque->configurer && $canbedeleted) {
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Delete").'</a>';
}
@ -796,15 +799,13 @@ if ($action == 'create')
/* */
/* ************************************************************************** */
if (GETPOST('id', 'int') && $action == 'edit' && $user->rights->banque->configurer)
{
if (GETPOST('id', 'int') && $action == 'edit' && $user->rights->banque->configurer) {
$object = new Account($db);
$object->fetch(GETPOST('id', 'int'));
print load_fiche_titre($langs->trans("EditFinancialAccount"), '', 'bank_account');
if ($conf->use_javascript_ajax)
{
if ($conf->use_javascript_ajax) {
print "\n".'<script type="text/javascript" language="javascript">';
print 'jQuery(document).ready(function () {
jQuery("#selecttype").change(function() {
@ -853,7 +854,9 @@ if ($action == 'create')
print '</td>';
print '<td class="maxwidth200onsmartphone">';
$selectedcode = $object->currency_code;
if (!$selectedcode) $selectedcode = $conf->currency;
if (!$selectedcode) {
$selectedcode = $conf->currency;
}
print $form->selectCurrency((GETPOSTISSET("account_currency_code") ? GETPOST("account_currency_code") : $selectedcode), 'account_currency_code');
//print $langs->trans("Currency".$conf->currency);
//print '<input type="hidden" name="account_currency_code" value="'.$conf->currency.'">';
@ -868,20 +871,24 @@ if ($action == 'create')
// Country
$object->country_id = $object->country_id ? $object->country_id : $mysoc->country_id;
$selectedcode = $object->country_code;
if (GETPOSTISSET("account_country_id")) $selectedcode = GETPOST("account_country_id");
elseif (empty($selectedcode)) $selectedcode = $mysoc->country_code;
if (GETPOSTISSET("account_country_id")) {
$selectedcode = GETPOST("account_country_id");
} elseif (empty($selectedcode)) {
$selectedcode = $mysoc->country_code;
}
$object->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
print '<tr><td class="fieldrequired">'.$langs->trans("Country").'</td>';
print '<td class="maxwidth200onsmartphone">';
print $form->select_country($selectedcode, 'account_country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
if ($user->admin) {
print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
}
print '</td></tr>';
// State
print '<tr><td>'.$langs->trans('State').'</td><td class="maxwidth200onsmartphone">';
if ($selectedcode)
{
if ($selectedcode) {
print $formcompany->select_state(GETPOSTISSET("account_state_id") ? GETPOST("account_state_id") : $object->state_id, $selectedcode, 'account_state_id');
} else {
print $countrynotdefined;
@ -892,9 +899,13 @@ if ($action == 'create')
print '<tr><td>'.$langs->trans("Conciliable").'</td>';
print '<td>';
$conciliate = $object->canBeConciliated();
if ($conciliate == -2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')';
elseif ($conciliate == -3) print $langs->trans("No").' ('.$langs->trans("Closed").')';
else print '<input type="checkbox" class="flat" name="norappro"'.(($conciliate > 0) ? '' : ' checked="checked"').'"> '.$langs->trans("DisableConciliation");
if ($conciliate == -2) {
print $langs->trans("No").' ('.$langs->trans("CashAccount").')';
} elseif ($conciliate == -3) {
print $langs->trans("No").' ('.$langs->trans("Closed").')';
} else {
print '<input type="checkbox" class="flat" name="norappro"'.(($conciliate > 0) ? '' : ' checked="checked"').'"> '.$langs->trans("DisableConciliation");
}
print '</td></tr>';
// Balance
@ -910,14 +921,12 @@ if ($action == 'create')
print '</td></tr>';
// Tags-Categories
if ($conf->categorie->enabled)
{
if ($conf->categorie->enabled) {
print '<tr><td class="tdtop">'.$langs->trans("Categories").'</td><td>';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1);
$c = new Categorie($db);
$cats = $c->containing($object->id, Categorie::TYPE_ACCOUNT);
if (is_array($cats))
{
if (is_array($cats)) {
foreach ($cats as $cat) {
$arrayselected[] = $cat->id;
}
@ -939,8 +948,7 @@ if ($action == 'create')
$parameters = array();
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (empty($reshook))
{
if (empty($reshook)) {
print $object->showOptionals($extrafields, 'edit', $parameters);
}
@ -969,8 +977,7 @@ if ($action == 'create')
print '</td></tr>';
// Accountancy journal
if (!empty($conf->accounting->enabled))
{
if (!empty($conf->accounting->enabled)) {
print '<tr><td class="fieldrequired">'.$langs->trans("AccountancyJournal").'</td>';
print '<td>';
print $formaccounting->select_journal($object->fk_accountancy_journal, 'fk_accountancy_journal', 4, 1, 0, 0);
@ -979,8 +986,7 @@ if ($action == 'create')
print '</table>';
if ($_POST["type"] == Account::TYPE_SAVINGS || $_POST["type"] == Account::TYPE_CURRENT)
{
if ($_POST["type"] == Account::TYPE_SAVINGS || $_POST["type"] == Account::TYPE_CURRENT) {
print '<br>';
//print '<div class="underbanner clearboth"></div>';
@ -1019,7 +1025,9 @@ if ($action == 'create')
$ibankey = FormBank::getIBANLabel($object);
$bickey = "BICNumber";
if ($object->getCountryCode() == 'IN') $bickey = "SWIFT";
if ($object->getCountryCode() == 'IN') {
$bickey = "SWIFT";
}
// IBAN
print '<tr><td>'.$langs->trans($ibankey).'</td>';
@ -1028,12 +1036,12 @@ if ($action == 'create')
print '<tr><td>'.$langs->trans($bickey).'</td>';
print '<td><input class="minwidth150 maxwidth200onsmartphone" maxlength="11" type="text" class="flat" name="bic" value="'.$object->bic.'"></td></tr>';
if ($conf->prelevement->enabled){
if ($conf->prelevement->enabled) {
print '<tr><td>'.$langs->trans("ICS").'</td>';
print '<td><input class="minwidth150 maxwidth200onsmartphone" maxlength="32" type="text" class="flat" name="ics" value="'.$object->ics.'"></td></tr>';
}
if ($conf->paymentbybanktransfer->enabled){
if ($conf->paymentbybanktransfer->enabled) {
print '<tr><td>'.$langs->trans("ICSTransfer").'</td>';
print '<td><input class="minwidth150 maxwidth200onsmartphone" maxlength="32" type="text" class="flat" name="ics_transfer" value="'.$object->ics_transfer.'"></td></tr>';
}

View File

@ -36,8 +36,9 @@ $langs->loadLangs(array('banks', 'categories'));
$action = GETPOST('action', 'aZ09');
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
if (!$user->rights->banque->configurer)
accessforbidden();
if (!$user->rights->banque->configurer) {
accessforbidden();
}
$bankcateg = new BankCateg($db);
$categid = GETPOST('categid');
@ -49,8 +50,7 @@ $label = GETPOST("label");
* Actions
*/
if (GETPOST('add'))
{
if (GETPOST('add')) {
if ($label) {
$bankcateg = new BankCateg($db);
$bankcateg->label = GETPOST('label');
@ -85,7 +85,9 @@ llxHeader();
print load_fiche_titre($langs->trans("RubriquesTransactions"), '', 'object_category');
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
@ -104,8 +106,7 @@ print '<td></td>';
print "</tr>\n";
// Line to add category
if ($action != 'edit')
{
if ($action != 'edit') {
print '<tr class="oddeven">';
print '<td>&nbsp;</td><td><input name="label" type="text" class="maxwidth100"></td>';
print '<td></td>';
@ -120,19 +121,16 @@ $sql .= " WHERE entity = ".$conf->entity;
$sql .= " ORDER BY rowid";
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0; $total = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $db->fetch_object($result);
print '<tr class="oddeven">';
print '<td>'.$objp->rowid.'</td>';
if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid)
{
if (GETPOST('action', 'aZ09') == 'edit' && GETPOST("categid") == $objp->rowid) {
print '<td colspan="3">';
print '<input type="hidden" name="categid" value="'.$objp->rowid.'">';
print '<input name="label" type="text" size=45 value="'.$objp->label.'">';

File diff suppressed because it is too large Load Diff

View File

@ -211,42 +211,36 @@ class BankCateg // extends CommonObject
$this->db->begin();
// Delete link between tag and bank account
if (!$error)
{
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
$sql .= " WHERE fk_categorie = ".$this->id;
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
}
// Delete link between tag and bank lines
if (!$error)
{
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class";
$sql .= " WHERE fk_categ = ".$this->id;
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
}
// Delete bank categ
if (!$error)
{
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ";
$sql .= " WHERE rowid=".$this->id;
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}

View File

@ -195,7 +195,9 @@ class PaymentVarious extends CommonObject
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."payment_various SET";
if ($this->tms) $sql .= " tms='".$this->db->idate($this->tms)."',";
if ($this->tms) {
$sql .= " tms='".$this->db->idate($this->tms)."',";
}
$sql .= " datep='".$this->db->idate($this->datep)."',";
$sql .= " datev='".$this->db->idate($this->datev)."',";
$sql .= " sens=".(int) $this->sens.",";
@ -222,7 +224,9 @@ class PaymentVarious extends CommonObject
if (!$notrigger) {
// Call trigger
$result = $this->call_trigger('PAYMENT_VARIOUS_MODIFY', $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
// End call triggers
}
@ -272,10 +276,8 @@ class PaymentVarious extends CommonObject
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -323,7 +325,9 @@ class PaymentVarious extends CommonObject
// Call trigger
$result = $this->call_trigger('PAYMENT_VARIOUS_DELETE', $user);
if ($result < 0) return -1;
if ($result < 0) {
return -1;
}
// End call triggers
@ -409,23 +413,19 @@ class PaymentVarious extends CommonObject
}
// Check parameters
if (!$this->label)
{
if (!$this->label) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
return -3;
}
if ($this->amount < 0 || $this->amount == '')
{
if ($this->amount < 0 || $this->amount == '') {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
return -5;
}
if (!empty($conf->banque->enabled) && (empty($this->fk_account) || $this->fk_account <= 0))
{
if (!empty($conf->banque->enabled) && (empty($this->fk_account) || $this->fk_account <= 0)) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount"));
return -6;
}
if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0))
{
if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0)) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
return -7;
}
@ -440,7 +440,9 @@ class PaymentVarious extends CommonObject
$sql .= ", amount";
$sql .= ", fk_typepayment";
$sql .= ", num_payment";
if ($this->note) $sql .= ", note";
if ($this->note) {
$sql .= ", note";
}
$sql .= ", label";
$sql .= ", accountancy_code";
$sql .= ", subledger_account";
@ -457,7 +459,9 @@ class PaymentVarious extends CommonObject
$sql .= ", ".price2num($this->amount);
$sql .= ", '".$this->db->escape($this->type_payment)."'";
$sql .= ", '".$this->db->escape($this->num_payment)."'";
if ($this->note) $sql .= ", '".$this->db->escape($this->note)."'";
if ($this->note) {
$sql .= ", '".$this->db->escape($this->note)."'";
}
$sql .= ", '".$this->db->escape($this->label)."'";
$sql .= ", '".$this->db->escape($this->accountancy_code)."'";
$sql .= ", '".$this->db->escape($this->subledger_account)."'";
@ -470,26 +474,27 @@ class PaymentVarious extends CommonObject
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_various");
$this->ref = $this->id;
if ($this->id > 0)
{
if (!empty($conf->banque->enabled) && !empty($this->amount))
{
if ($this->id > 0) {
if (!empty($conf->banque->enabled) && !empty($this->amount)) {
// Insert into llx_bank
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$acc = new Account($this->db);
$result = $acc->fetch($this->fk_account);
if ($result <= 0) dol_print_error($this->db);
if ($result <= 0) {
dol_print_error($this->db);
}
// Insert payment into llx_bank
// Add link 'payment_various' in bank_url between payment and bank transaction
$sign = 1;
if ($this->sens == '0') $sign = -1;
if ($this->sens == '0') {
$sign = -1;
}
$bank_line_id = $acc->addline(
$this->datep,
@ -514,21 +519,18 @@ class PaymentVarious extends CommonObject
$error++;
}
if (!$error)
{
if (!$error) {
// Add link 'payment_various' in bank_url between payment and bank transaction
$url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id=';
$result = $acc->add_url_line($bank_line_id, $this->id, $url, "(VariousPayment)", "payment_various");
if ($result <= 0)
{
if ($result <= 0) {
$this->error = $acc->error;
$error++;
}
}
if ($result <= 0)
{
if ($result <= 0) {
$this->error = $acc->error;
$error++;
}
@ -536,12 +538,15 @@ class PaymentVarious extends CommonObject
// Call trigger
$result = $this->call_trigger('PAYMENT_VARIOUS_CREATE', $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
// End call triggers
} else $error++;
} else {
$error++;
}
if (!$error)
{
if (!$error) {
$this->db->commit();
return $this->id;
} else {
@ -568,8 +573,7 @@ class PaymentVarious extends CommonObject
$sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_various SET fk_bank = '.$id_bank;
$sql .= ' WHERE rowid = '.$this->id;
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
return 1;
} else {
dol_print_error($this->db);
@ -607,21 +611,37 @@ class PaymentVarious extends CommonObject
} elseif ($mode == 1) {
return $langs->trans($this->statuts_short[$status]);
} elseif ($mode == 2) {
if ($status == 0) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts_short[$status]);
elseif ($status == 1) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts_short[$status]);
elseif ($status == 2) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]);
if ($status == 0) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts_short[$status]);
} elseif ($status == 1) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts_short[$status]);
} elseif ($status == 2) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]);
}
} elseif ($mode == 3) {
if ($status == 0 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
elseif ($status == 1 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
elseif ($status == 2 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
if ($status == 0 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
} elseif ($status == 1 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
} elseif ($status == 2 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
}
} elseif ($mode == 4) {
if ($status == 0 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]);
elseif ($status == 1 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]);
elseif ($status == 2 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]);
if ($status == 0 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]);
} elseif ($status == 1 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]);
} elseif ($status == 2 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]);
}
} elseif ($mode == 5) {
if ($status == 0 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
elseif ($status == 1 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
elseif ($status == 2 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
if ($status == 0 && !empty($this->statuts_short[$status])) {
return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
} elseif ($status == 1 && !empty($this->statuts_short[$status])) {
return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
} elseif ($status == 2 && !empty($this->statuts_short[$status])) {
return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
}
}
}
@ -641,7 +661,9 @@ class PaymentVarious extends CommonObject
global $db, $conf, $langs, $hookmanager;
global $langs;
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
if (!empty($conf->dol_no_mouse_hover)) {
$notooltip = 1; // Force disable tooltips
}
$result = '';
@ -651,19 +673,20 @@ class PaymentVarious extends CommonObject
$url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$this->id;
if ($option != 'nolink')
{
if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
$add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
}
$linkclose = '';
if (empty($notooltip))
{
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
if (empty($notooltip)) {
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowMyObject");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
@ -676,15 +699,21 @@ class PaymentVarious extends CommonObject
$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $linkclose = $hookmanager->resPrint;
*/
} else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
} else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
$linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
if ($withpicto) {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto != 2) {
$result .= $this->ref;
}
$result .= $linkend;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
@ -692,8 +721,11 @@ class PaymentVarious extends CommonObject
$hookmanager->initHooks(array('variouspayment'));
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $result = $hookmanager->resPrint;
else $result .= $hookmanager->resPrint;
if ($reshook > 0) {
$result = $hookmanager->resPrint;
} else {
$result .= $hookmanager->resPrint;
}
return $result;
}
@ -713,21 +745,17 @@ class PaymentVarious extends CommonObject
dol_syslog(get_class($this).'::info', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
if ($obj->fk_user_author)
{
if ($obj->fk_user_author) {
$cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser;
}
$this->date_creation = $this->db->jdate($obj->datec);
if ($obj->fk_user_modif)
{
if ($obj->fk_user_modif) {
$muser = new User($this->db);
$muser->fetch($obj->fk_user_modif);
$this->user_modif = $muser;
@ -755,11 +783,9 @@ class PaymentVarious extends CommonObject
$sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".$banklineid;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj)
{
if ($obj) {
$alreadydispatched = $obj->nb;
}
} else {
@ -767,8 +793,7 @@ class PaymentVarious extends CommonObject
return -1;
}
if ($alreadydispatched)
{
if ($alreadydispatched) {
return 1;
}
return 0;

View File

@ -44,25 +44,32 @@ if ($user->socid) {
$action = '';
$socid = $user->socid;
}
if ($user->socid)
if ($user->socid) {
$socid = $user->socid;
}
// Get parameters
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; }
if (empty($page) || $page == -1) {
$page = 0;
}
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder)
if (!$sortorder) {
$sortorder = "ASC";
if (!$sortfield)
}
if (!$sortfield) {
$sortfield = "name";
}
$object = new Account($db);
if ($id > 0 || !empty($ref)) $object->fetch($id, $ref);
if ($id > 0 || !empty($ref)) {
$object->fetch($id, $ref);
}
$result = restrictedArea($user, 'banque', $object->id, 'bank_account', '', '');
@ -71,8 +78,7 @@ $result = restrictedArea($user, 'banque', $object->id, 'bank_account', '', '');
* Actions
*/
if ($object->id > 0)
{
if ($object->id > 0) {
$object->fetch_thirdparty();
$upload_dir = $conf->bank->dir_output."/".dol_sanitizeFileName($object->ref);
}

View File

@ -35,17 +35,20 @@ $WIDTH = DolGraph::getDefaultGraphSizeForStats('width', 768);
$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height', 200);
// Security check
if (isset($_GET["account"]) || isset($_GET["ref"]))
{
if (isset($_GET["account"]) || isset($_GET["ref"])) {
$id = isset($_GET["account"]) ? $_GET["account"] : (isset($_GET["ref"]) ? $_GET["ref"] : '');
}
$fieldid = isset($_GET["ref"]) ? 'ref' : 'rowid';
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid);
$account = GETPOST("account");
$mode = 'standard';
if (GETPOST("mode") == 'showalltime') $mode = 'showalltime';
if (GETPOST("mode") == 'showalltime') {
$mode = 'showalltime';
}
$error = 0;
@ -63,24 +66,25 @@ $datetime = dol_now();
$year = dol_print_date($datetime, "%Y");
$month = dol_print_date($datetime, "%m");
$day = dol_print_date($datetime, "%d");
if (GETPOST("year")) $year = sprintf("%04d", GETPOST("year"));
if (GETPOST("month")) $month = sprintf("%02d", GETPOST("month"));
if (GETPOST("year")) {
$year = sprintf("%04d", GETPOST("year"));
}
if (GETPOST("month")) {
$month = sprintf("%02d", GETPOST("month"));
}
$object = new Account($db);
if ($_GET["account"] && !preg_match('/,/', $_GET["account"])) // if for a particular account and not a list
{
if ($_GET["account"] && !preg_match('/,/', $_GET["account"])) { // if for a particular account and not a list
$result = $object->fetch(GETPOST("account", "int"));
}
if ($_GET["ref"])
{
if ($_GET["ref"]) {
$result = $object->fetch(0, GETPOST("ref"));
$account = $object->id;
}
$result = dol_mkdir($conf->bank->dir_temp);
if ($result < 0)
{
if ($result < 0) {
$langs->load("errors");
$error++;
setEventMessages($langs->trans("ErrorFailedToCreateDir"), null, 'errors');
@ -91,11 +95,12 @@ if ($result < 0)
$sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= " WHERE b.fk_account = ba.rowid";
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
if ($account && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$account.")";
if ($account && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$account.")";
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$obj = $db->fetch_object($resql);
$min = $db->jdate($obj->min);
@ -103,7 +108,9 @@ if ($result < 0)
} else {
dol_print_error($db);
}
if (empty($min)) $min = dol_now() - 3600 * 24;
if (empty($min)) {
$min = dol_now() - 3600 * 24;
}
$log = "graph.php: min=".$min." max=".$max;
dol_syslog($log);
@ -111,15 +118,13 @@ if ($result < 0)
// Tableau 1
if ($mode == 'standard')
{
if ($mode == 'standard') {
// Loading table $amounts
$amounts = array();
$monthnext = $month + 1;
$yearnext = $year;
if ($monthnext > 12)
{
if ($monthnext > 12) {
$monthnext = 1;
$yearnext++;
}
@ -132,16 +137,16 @@ if ($result < 0)
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
$sql .= " AND b.datev >= '".$db->escape($year)."-".$db->escape($month)."-01 00:00:00'";
$sql .= " AND b.datev < '".$db->escape($yearnext)."-".$db->escape($monthnext)."-01 00:00:00'";
if ($account && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$account.")";
if ($account && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$account.")";
}
$sql .= " GROUP BY date_format(b.datev,'%Y%m%d')";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$amounts[$row[0]] = $row[1];
$i++;
@ -160,11 +165,12 @@ if ($result < 0)
$sql .= " WHERE b.fk_account = ba.rowid";
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
$sql .= " AND b.datev < '".$db->escape($year)."-".sprintf("%02s", $month)."-01'";
if ($account && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$account.")";
if ($account && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$account.")";
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$row = $db->fetch_row($resql);
$solde = $row[0];
$db->free($resql);
@ -185,11 +191,9 @@ if ($result < 0)
$xmonth = substr($textdate, 4, 2);
$i = 0;
while ($xmonth == $month)
{
while ($xmonth == $month) {
$subtotal = $subtotal + (isset($amounts[$textdate]) ? $amounts[$textdate] : 0);
if ($day > time())
{
if ($day > time()) {
$datas[$i] = ''; // Valeur speciale permettant de ne pas tracer le graph
} else {
$datas[$i] = $solde + $subtotal;
@ -219,18 +223,25 @@ if ($result < 0)
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/balance".$account."-".$year.$month.".png";
$title = $langs->transnoentities("Balance").' - '.$langs->transnoentities("Month").': '.$month.' '.$langs->transnoentities("Year").': '.$year;
$graph_datas = array();
foreach ($datas as $i => $val)
{
foreach ($datas as $i => $val) {
$graph_datas[$i] = array(isset($labels[$i]) ? $labels[$i] : '', $datas[$i]);
if ($object->min_desired) array_push($graph_datas[$i], $datamin[$i]);
if ($object->min_allowed) array_push($graph_datas[$i], $dataall[$i]);
if ($object->min_desired) {
array_push($graph_datas[$i], $datamin[$i]);
}
if ($object->min_allowed) {
array_push($graph_datas[$i], $dataall[$i]);
}
}
$px1 = new DolGraph();
$px1->SetData($graph_datas);
$arraylegends = array($langs->transnoentities("Balance"));
if ($object->min_desired) array_push($arraylegends, $langs->transnoentities("BalanceMinimalDesired"));
if ($object->min_allowed) array_push($arraylegends, $langs->transnoentities("BalanceMinimalAllowed"));
if ($object->min_desired) {
array_push($arraylegends, $langs->transnoentities("BalanceMinimalDesired"));
}
if ($object->min_allowed) {
array_push($arraylegends, $langs->transnoentities("BalanceMinimalAllowed"));
}
$px1->SetLegend($arraylegends);
$px1->SetLegendWidthMin(180);
$px1->SetMaxValue($px1->GetCeilMaxValue() < 0 ? 0 : $px1->GetCeilMaxValue());
@ -257,8 +268,7 @@ if ($result < 0)
// Graph Balance for the year
if ($mode == 'standard')
{
if ($mode == 'standard') {
// Loading table $amounts
$amounts = array();
$sql = "SELECT date_format(b.datev,'%Y%m%d')";
@ -269,16 +279,16 @@ if ($result < 0)
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
$sql .= " AND b.datev >= '".$db->escape($year)."-01-01 00:00:00'";
$sql .= " AND b.datev <= '".$db->escape($year)."-12-31 23:59:59'";
if ($account && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$account.")";
if ($account && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$account.")";
}
$sql .= " GROUP BY date_format(b.datev,'%Y%m%d')";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$amounts[$row[0]] = $row[1];
$i++;
@ -297,11 +307,12 @@ if ($result < 0)
$sql .= " WHERE b.fk_account = ba.rowid";
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
$sql .= " AND b.datev < '".$db->escape($year)."-01-01'";
if ($account && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$account.")";
if ($account && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$account.")";
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$row = $db->fetch_row($resql);
$solde = $row[0];
$db->free($resql);
@ -323,11 +334,9 @@ if ($result < 0)
$xday = substr($textdate, 6, 2);
$i = 0;
while ($xyear == $year && $day <= $datetime)
{
while ($xyear == $year && $day <= $datetime) {
$subtotal = $subtotal + (isset($amounts[$textdate]) ? $amounts[$textdate] : 0);
if ($day > $now)
{
if ($day > $now) {
$datas[$i] = ''; // Valeur speciale permettant de ne pas tracer le graph
} else {
$datas[$i] = $solde + $subtotal;
@ -351,17 +360,24 @@ if ($result < 0)
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/balance".$account."-".$year.".png";
$title = $langs->transnoentities("Balance").' - '.$langs->transnoentities("Year").': '.$year;
$graph_datas = array();
foreach ($datas as $i => $val)
{
foreach ($datas as $i => $val) {
$graph_datas[$i] = array(isset($labels[$i]) ? $labels[$i] : '', $datas[$i]);
if ($object->min_desired) array_push($graph_datas[$i], $datamin[$i]);
if ($object->min_allowed) array_push($graph_datas[$i], $dataall[$i]);
if ($object->min_desired) {
array_push($graph_datas[$i], $datamin[$i]);
}
if ($object->min_allowed) {
array_push($graph_datas[$i], $dataall[$i]);
}
}
$px2 = new DolGraph();
$px2->SetData($graph_datas);
$arraylegends = array($langs->transnoentities("Balance"));
if ($object->min_desired) array_push($arraylegends, $langs->transnoentities("BalanceMinimalDesired"));
if ($object->min_allowed) array_push($arraylegends, $langs->transnoentities("BalanceMinimalAllowed"));
if ($object->min_desired) {
array_push($arraylegends, $langs->transnoentities("BalanceMinimalDesired"));
}
if ($object->min_allowed) {
array_push($arraylegends, $langs->transnoentities("BalanceMinimalAllowed"));
}
$px2->SetLegend($arraylegends);
$px2->SetLegendWidthMin(180);
$px2->SetMaxValue($px2->GetCeilMaxValue() < 0 ? 0 : $px2->GetCeilMaxValue());
@ -389,8 +405,7 @@ if ($result < 0)
// Graph 3 - Balance for all time line
if ($mode == 'showalltime')
{
if ($mode == 'showalltime') {
// Loading table $amounts
$amounts = array();
@ -400,17 +415,17 @@ if ($result < 0)
$sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= " WHERE b.fk_account = ba.rowid";
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
if ($account && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$account.")";
if ($account && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$account.")";
}
$sql .= " GROUP BY date_format(b.datev,'%Y%m%d')";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$amounts[$row[0]] = $row[1];
$i++;
@ -434,12 +449,10 @@ if ($result < 0)
$textdate = strftime("%Y%m%d", $day);
//print "x".$textdate;
$i = 0;
while ($day <= ($max + 86400)) // On va au dela du dernier jour
{
while ($day <= ($max + 86400)) { // On va au dela du dernier jour
$subtotal = $subtotal + (isset($amounts[$textdate]) ? $amounts[$textdate] : 0);
//print strftime ("%e %d %m %y",$day)." ".$subtotal."\n<br>";
if ($day > ($max + 86400))
{
if ($day > ($max + 86400)) {
$datas[$i] = ''; // Valeur speciale permettant de ne pas tracer le graph
} else {
$datas[$i] = 0 + $solde + $subtotal;
@ -462,18 +475,25 @@ if ($result < 0)
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/balance".$account.".png";
$title = $langs->transnoentities("Balance")." - ".$langs->transnoentities("AllTime");
$graph_datas = array();
foreach ($datas as $i => $val)
{
foreach ($datas as $i => $val) {
$graph_datas[$i] = array(isset($labels[$i]) ? $labels[$i] : '', $datas[$i]);
if ($object->min_desired) array_push($graph_datas[$i], $datamin[$i]);
if ($object->min_allowed) array_push($graph_datas[$i], $dataall[$i]);
if ($object->min_desired) {
array_push($graph_datas[$i], $datamin[$i]);
}
if ($object->min_allowed) {
array_push($graph_datas[$i], $dataall[$i]);
}
}
$px3 = new DolGraph();
$px3->SetData($graph_datas);
$arraylegends = array($langs->transnoentities("Balance"));
if ($object->min_desired) array_push($arraylegends, $langs->transnoentities("BalanceMinimalDesired"));
if ($object->min_allowed) array_push($arraylegends, $langs->transnoentities("BalanceMinimalAllowed"));
if ($object->min_desired) {
array_push($arraylegends, $langs->transnoentities("BalanceMinimalDesired"));
}
if ($object->min_allowed) {
array_push($arraylegends, $langs->transnoentities("BalanceMinimalAllowed"));
}
$px3->SetLegend($arraylegends);
$px3->SetLegendWidthMin(180);
$px3->SetMaxValue($px3->GetCeilMaxValue() < 0 ? 0 : $px3->GetCeilMaxValue());
@ -499,16 +519,14 @@ if ($result < 0)
// Tableau 4a - Credit/Debit
if ($mode == 'standard')
{
if ($mode == 'standard') {
// Chargement du tableau $credits, $debits
$credits = array();
$debits = array();
$monthnext = $month + 1;
$yearnext = $year;
if ($monthnext > 12)
{
if ($monthnext > 12) {
$monthnext = 1;
$yearnext++;
}
@ -522,16 +540,16 @@ if ($result < 0)
$sql .= " AND b.datev >= '".$db->escape($year)."-".$db->escape($month)."-01 00:00:00'";
$sql .= " AND b.datev < '".$db->escape($yearnext)."-".$db->escape($monthnext)."-01 00:00:00'";
$sql .= " AND b.amount > 0";
if ($account && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$account.")";
if ($account && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$account.")";
}
$sql .= " GROUP BY date_format(b.datev,'%d')";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$credits[$row[0]] = $row[1];
$i++;
@ -543,8 +561,7 @@ if ($result < 0)
$monthnext = $month + 1;
$yearnext = $year;
if ($monthnext > 12)
{
if ($monthnext > 12) {
$monthnext = 1;
$yearnext++;
}
@ -558,14 +575,14 @@ if ($result < 0)
$sql .= " AND b.datev >= '".$db->escape($year)."-".$db->escape($month)."-01 00:00:00'";
$sql .= " AND b.datev < '".$db->escape($yearnext)."-".$db->escape($monthnext)."-01 00:00:00'";
$sql .= " AND b.amount < 0";
if ($account && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$account.")";
if ($account && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$account.")";
}
$sql .= " GROUP BY date_format(b.datev,'%d')";
$resql = $db->query($sql);
if ($resql)
{
while ($row = $db->fetch_row($resql))
{
if ($resql) {
while ($row = $db->fetch_row($resql)) {
$debits[$row[0]] = abs($row[1]);
}
$db->free($resql);
@ -578,8 +595,7 @@ if ($result < 0)
$labels = array();
$data_credit = array();
$data_debit = array();
for ($i = 0; $i < 31; $i++)
{
for ($i = 0; $i < 31; $i++) {
$data_credit[$i] = isset($credits[substr("0".($i + 1), -2)]) ? $credits[substr("0".($i + 1), -2)] : 0;
$data_debit[$i] = isset($debits[substr("0".($i + 1), -2)]) ? $debits[substr("0".($i + 1), -2)] : 0;
$labels[$i] = sprintf("%02d", $i + 1);
@ -591,8 +607,7 @@ if ($result < 0)
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/movement".$account."-".$year.$month.".png";
$title = $langs->transnoentities("BankMovements").' - '.$langs->transnoentities("Month").': '.$month.' '.$langs->transnoentities("Year").': '.$year;
$graph_datas = array();
foreach ($data_credit as $i => $val)
{
foreach ($data_credit as $i => $val) {
$graph_datas[$i] = array($labels[$i], $data_credit[$i], $data_debit[$i]);
}
$px4 = new DolGraph();
@ -621,8 +636,7 @@ if ($result < 0)
// Tableau 4b - Credit/Debit
if ($mode == 'standard')
{
if ($mode == 'standard') {
// Chargement du tableau $credits, $debits
$credits = array();
$debits = array();
@ -635,16 +649,16 @@ if ($result < 0)
$sql .= " AND b.datev >= '".$db->escape($year)."-01-01 00:00:00'";
$sql .= " AND b.datev <= '".$db->escape($year)."-12-31 23:59:59'";
$sql .= " AND b.amount > 0";
if ($account && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$account.")";
if ($account && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$account.")";
}
$sql .= " GROUP BY date_format(b.datev,'%m');";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
$credits[$row[0]] = $row[1];
$i++;
@ -662,14 +676,14 @@ if ($result < 0)
$sql .= " AND b.datev >= '".$db->escape($year)."-01-01 00:00:00'";
$sql .= " AND b.datev <= '".$db->escape($year)."-12-31 23:59:59'";
$sql .= " AND b.amount < 0";
if ($account && $_GET["option"] != 'all') $sql .= " AND b.fk_account IN (".$account.")";
if ($account && $_GET["option"] != 'all') {
$sql .= " AND b.fk_account IN (".$account.")";
}
$sql .= " GROUP BY date_format(b.datev,'%m')";
$resql = $db->query($sql);
if ($resql)
{
while ($row = $db->fetch_row($resql))
{
if ($resql) {
while ($row = $db->fetch_row($resql)) {
$debits[$row[0]] = abs($row[1]);
}
$db->free($resql);
@ -682,8 +696,7 @@ if ($result < 0)
$labels = array();
$data_credit = array();
$data_debit = array();
for ($i = 0; $i < 12; $i++)
{
for ($i = 0; $i < 12; $i++) {
$data_credit[$i] = isset($credits[substr("0".($i + 1), -2)]) ? $credits[substr("0".($i + 1), -2)] : 0;
$data_debit[$i] = isset($debits[substr("0".($i + 1), -2)]) ? $debits[substr("0".($i + 1), -2)] : 0;
$labels[$i] = dol_print_date(dol_mktime(12, 0, 0, $i + 1, 1, 2000), "%b");
@ -695,8 +708,7 @@ if ($result < 0)
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=banque_temp&file='."/movement".$account."-".$year.".png";
$title = $langs->transnoentities("BankMovements").' - '.$langs->transnoentities("Year").': '.$year;
$graph_datas = array();
foreach ($data_credit as $i => $val)
{
foreach ($data_credit as $i => $val) {
$graph_datas[$i] = array($labels[$i], $data_credit[$i], $data_debit[$i]);
}
$px5 = new DolGraph();
@ -732,14 +744,11 @@ print dol_get_fiche_head($head, 'graph', $langs->trans("FinancialAccount"), 0, '
$linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
if ($account)
{
if (!preg_match('/,/', $account))
{
if ($account) {
if (!preg_match('/,/', $account)) {
$moreparam = '&month='.$month.'&year='.$year.($mode == 'showalltime' ? '&mode=showalltime' : '');
if ($_GET["option"] != 'all')
{
if ($_GET["option"] != 'all') {
$morehtml = '<a href="'.$_SERVER["PHP_SELF"].'?account='.$account.'&option=all'.$moreparam.'">'.$langs->trans("ShowAllAccounts").'</a>';
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', '', $moreparam, 0, '', '', 1);
} else {
@ -750,12 +759,13 @@ if ($account)
} else {
$bankaccount = new Account($db);
$listid = explode(',', $account);
foreach ($listid as $key => $id)
{
foreach ($listid as $key => $id) {
$bankaccount->fetch($id);
$bankaccount->label = $bankaccount->ref;
print $bankaccount->getNomUrl(1);
if ($key < (count($listid) - 1)) print ', ';
if ($key < (count($listid) - 1)) {
print ', ';
}
}
}
} else {
@ -769,8 +779,7 @@ print '<table class="notopnoleftnoright" width="100%">';
// Navigation links
print '<tr><td class="right">'.$morehtml.' &nbsp; &nbsp; ';
if ($mode == 'showalltime')
{
if ($mode == 'showalltime') {
print '<a href="'.$_SERVER["PHP_SELF"].'?account='.$account.(GETPOST("option") != 'all' ? '' : '&option=all').'">';
print $langs->trans("GoBack");
print '</a>';
@ -785,12 +794,15 @@ print '</table>';
// Graphs
if ($mode == 'standard')
{
if ($mode == 'standard') {
$prevyear = $year; $nextyear = $year;
$prevmonth = $month - 1; $nextmonth = $month + 1;
if ($prevmonth < 1) { $prevmonth = 12; $prevyear--; }
if ($nextmonth > 12) { $nextmonth = 1; $nextyear++; }
if ($prevmonth < 1) {
$prevmonth = 12; $prevyear--;
}
if ($nextmonth > 12) {
$nextmonth = 1; $nextyear++;
}
// For month
$link = "<a href='".$_SERVER["PHP_SELF"]."?account=".$account.(GETPOST("option") != 'all' ? '' : '&option=all')."&year=".$prevyear."&month=".$prevmonth."'>".img_previous('', 'class="valignbottom"')."</a> ".$langs->trans("Month")." <a href='".$_SERVER["PHP_SELF"]."?account=".$account.(GETPOST("option") != 'all' ? '' : '&option=all')."&year=".$nextyear."&month=".$nextmonth."'>".img_next('', 'class="valignbottom"')."</a>";
@ -820,8 +832,7 @@ if ($mode == 'standard')
print '</div>';
}
if ($mode == 'showalltime')
{
if ($mode == 'showalltime') {
print '<div class="center clearboth margintoponly">';
print $show3;
print '</div>';

View File

@ -37,10 +37,18 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
// Load translation files required by the page
$langs->loadLangs(array('banks', 'categories', 'compta', 'bills', 'other'));
if (!empty($conf->adherent->enabled)) $langs->load("members");
if (!empty($conf->don->enabled)) $langs->load("donations");
if (!empty($conf->loan->enabled)) $langs->load("loan");
if (!empty($conf->salaries->enabled)) $langs->load("salaries");
if (!empty($conf->adherent->enabled)) {
$langs->load("members");
}
if (!empty($conf->don->enabled)) {
$langs->load("donations");
}
if (!empty($conf->loan->enabled)) {
$langs->load("loan");
}
if (!empty($conf->salaries->enabled)) {
$langs->load("salaries");
}
$id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('account', 'int'));
@ -55,9 +63,13 @@ $cancel = GETPOST('cancel', 'alpha');
// Security check
$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', $fieldvalue, 'bank_account', '', '', $fieldtype);
if (!$user->rights->banque->lire && !$user->rights->banque->consolidate) accessforbidden();
if (!$user->rights->banque->lire && !$user->rights->banque->consolidate) {
accessforbidden();
}
$hookmanager->initHooks(array('bankline'));
@ -67,42 +79,36 @@ $hookmanager->initHooks(array('bankline'));
*/
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($cancel)
{
if ($backtopage)
{
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if ($cancel) {
if ($backtopage) {
header("Location: ".$backtopage);
exit;
}
}
if ($user->rights->banque->consolidate && $action == 'donext')
{
if ($user->rights->banque->consolidate && $action == 'donext') {
$al = new AccountLine($db);
$al->dateo_next($_GET["rowid"]);
} elseif ($user->rights->banque->consolidate && $action == 'doprev')
{
} elseif ($user->rights->banque->consolidate && $action == 'doprev') {
$al = new AccountLine($db);
$al->dateo_previous($_GET["rowid"]);
} elseif ($user->rights->banque->consolidate && $action == 'dvnext')
{
} elseif ($user->rights->banque->consolidate && $action == 'dvnext') {
$al = new AccountLine($db);
$al->datev_next($_GET["rowid"]);
} elseif ($user->rights->banque->consolidate && $action == 'dvprev')
{
} elseif ($user->rights->banque->consolidate && $action == 'dvprev') {
$al = new AccountLine($db);
$al->datev_previous($_GET["rowid"]);
}
if ($action == 'confirm_delete_categ' && $confirm == "yes" && $user->rights->banque->modifier)
{
if ($action == 'confirm_delete_categ' && $confirm == "yes" && $user->rights->banque->modifier) {
$cat1 = GETPOST("cat1", 'int');
if (!empty($rowid) && !empty($cat1)) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".$rowid." AND fk_categ = ".$cat1;
if (!$db->query($sql))
{
if (!$db->query($sql)) {
dol_print_error($db);
}
} else {
@ -110,8 +116,7 @@ if ($action == 'confirm_delete_categ' && $confirm == "yes" && $user->rights->ban
}
}
if ($user->rights->banque->modifier && $action == "update")
{
if ($user->rights->banque->modifier && $action == "update") {
$error = 0;
$acline = new AccountLine($db);
@ -121,21 +126,18 @@ if ($user->rights->banque->modifier && $action == "update")
$acsource->fetch($id);
$actarget = new Account($db);
if (GETPOST('accountid', 'int') > 0 && !$acline->rappro && !$acline->getVentilExportCompta()) // We ask to change bank account
{
if (GETPOST('accountid', 'int') > 0 && !$acline->rappro && !$acline->getVentilExportCompta()) { // We ask to change bank account
$actarget->fetch(GETPOST('accountid', 'int'));
} else {
$actarget->fetch($id);
}
if ($actarget->courant == Account::TYPE_CASH && GETPOST('value', 'alpha') != 'LIQ')
{
if ($actarget->courant == Account::TYPE_CASH && GETPOST('value', 'alpha') != 'LIQ') {
setEventMessages($langs->trans("ErrorCashAccountAcceptsOnlyCashMoney"), null, 'errors');
$error++;
}
if (!$error)
{
if (!$error) {
$db->begin();
$amount = price2num($_POST['amount']);
@ -144,43 +146,52 @@ if ($user->rights->banque->modifier && $action == "update")
$sql = "UPDATE ".MAIN_DB_PREFIX."bank";
$sql .= " SET ";
// Always opened
if (GETPOSTISSET('value')) $sql .= " fk_type='".$db->escape(GETPOST('value'))."',";
if (GETPOSTISSET('num_chq')) $sql .= " num_chq='".$db->escape(GETPOST("num_chq"))."',";
if (GETPOSTISSET('banque')) $sql .= " banque='".$db->escape(GETPOST("banque"))."',";
if (GETPOSTISSET('emetteur')) $sql .= " emetteur='".$db->escape(GETPOST("emetteur"))."',";
if (GETPOSTISSET('value')) {
$sql .= " fk_type='".$db->escape(GETPOST('value'))."',";
}
if (GETPOSTISSET('num_chq')) {
$sql .= " num_chq='".$db->escape(GETPOST("num_chq"))."',";
}
if (GETPOSTISSET('banque')) {
$sql .= " banque='".$db->escape(GETPOST("banque"))."',";
}
if (GETPOSTISSET('emetteur')) {
$sql .= " emetteur='".$db->escape(GETPOST("emetteur"))."',";
}
// Blocked when conciliated
if (!$acline->rappro)
{
if (GETPOSTISSET('label')) $sql .= " label = '".$db->escape(GETPOST("label"))."',";
if (GETPOSTISSET('amount')) $sql .= " amount= '".$db->escape($amount)."',";
if (GETPOSTISSET('dateomonth')) $sql .= " dateo = '".$db->idate($dateop)."',";
if (GETPOSTISSET('datevmonth')) $sql .= " datev = '".$db->idate($dateval)."',";
if (!$acline->rappro) {
if (GETPOSTISSET('label')) {
$sql .= " label = '".$db->escape(GETPOST("label"))."',";
}
if (GETPOSTISSET('amount')) {
$sql .= " amount= '".$db->escape($amount)."',";
}
if (GETPOSTISSET('dateomonth')) {
$sql .= " dateo = '".$db->idate($dateop)."',";
}
if (GETPOSTISSET('datevmonth')) {
$sql .= " datev = '".$db->idate($dateval)."',";
}
}
$sql .= " fk_account = ".$actarget->id;
$sql .= " WHERE rowid = ".$acline->id;
$result = $db->query($sql);
if (!$result)
{
if (!$result) {
$error++;
}
if (!$error)
{
if (!$error) {
$arrayofcategs = GETPOST('custcats', 'array');
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".$rowid;
if (!$db->query($sql))
{
if (!$db->query($sql)) {
$error++;
dol_print_error($db);
}
if (count($arrayofcategs))
{
foreach ($arrayofcategs as $val)
{
if (count($arrayofcategs)) {
foreach ($arrayofcategs as $val) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES (".$rowid.", ".$val.")";
if (!$db->query($sql))
{
if (!$db->query($sql)) {
$error++;
dol_print_error($db);
}
@ -189,8 +200,7 @@ if ($user->rights->banque->modifier && $action == "update")
}
}
if (!$error)
{
if (!$error) {
setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
$db->commit();
} else {
@ -201,32 +211,31 @@ if ($user->rights->banque->modifier && $action == "update")
}
// Reconcile
if ($user->rights->banque->consolidate && ($action == 'num_releve' || $action == 'setreconcile'))
{
if ($user->rights->banque->consolidate && ($action == 'num_releve' || $action == 'setreconcile')) {
$num_rel = trim($_POST["num_rel"]);
$rappro = $_POST['reconciled'] ? 1 : 0;
// Check parameters
if ($rappro && empty($num_rel))
{
if ($rappro && empty($num_rel)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountStatement")), null, 'errors');
$error++;
}
if (!$error)
{
if (!$error) {
$db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."bank";
$sql .= " SET num_releve=".($num_rel ? "'".$db->escape($num_rel)."'" : "null");
if (empty($num_rel)) $sql .= ", rappro = 0";
else $sql .= ", rappro = ".$rappro;
if (empty($num_rel)) {
$sql .= ", rappro = 0";
} else {
$sql .= ", rappro = ".$rappro;
}
$sql .= " WHERE rowid = ".$rowid;
dol_syslog("line.php", LOG_DEBUG);
$result = $db->query($sql);
if ($result)
{
if ($result) {
setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
$db->commit();
} else {
@ -262,11 +271,9 @@ $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
$sql .= " WHERE rowid=".$rowid;
$sql .= " ORDER BY dateo ASC";
$result = $db->query($sql);
if ($result)
{
if ($result) {
$i = 0; $total = 0;
if ($db->num_rows($result))
{
if ($db->num_rows($result)) {
$objp = $db->fetch_object($result);
$total = $total + $objp->amount;
@ -282,8 +289,7 @@ if ($result)
$bankline->load_previous_next_ref('', 'rowid');
// Confirmations
if ($action == 'delete_categ')
{
if ($action == 'delete_categ') {
print $form->formconfirm($_SERVER['PHP_SELF']."?rowid=".$rowid."&cat1=".GETPOST("fk_categ")."&orig_account=".$orig_account, $langs->trans("RemoveFromRubrique"), $langs->trans("RemoveFromRubriqueConfirm"), "confirm_delete_categ", '', 'yes', 1);
}
@ -310,8 +316,7 @@ if ($result)
// Bank account
print '<tr><td class="titlefield">'.$langs->trans("Account").'</td>';
print '<td>';
if (!$objp->rappro && !$bankline->getVentilExportCompta())
{
if (!$objp->rappro && !$bankline->getVentilExportCompta()) {
$form->select_comptes($acct->id, 'accountid', 0, '', 0);
} else {
print $acct->getNomUrl(1, 'transactions', 'reflabel');
@ -320,22 +325,22 @@ if ($result)
print '</tr>';
// Show links of bank transactions
if (count($links))
{
if (count($links)) {
print '<tr><td class="tdtop">'.$langs->trans("Links").'</td>';
print '<td>';
foreach ($links as $key=>$val)
{
if ($key) print '<br>';
foreach ($links as $key => $val) {
if ($key) {
print '<br>';
}
if ($links[$key]['type'] == 'payment') {
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
$paymenttmp = new Paiement($db);
$paymenttmp->fetch($links[$key]['url_id']);
$paymenttmp->ref = $langs->trans("Payment").' '.$paymenttmp->ref;
/*print '<a href="'.DOL_URL_ROOT.'/compta/paiement/card.php?id='.$links[$key]['url_id'].'">';
print img_object($langs->trans('Payment'),'payment').' ';
print $langs->trans("Payment");
print '</a>';*/
print img_object($langs->trans('Payment'),'payment').' ';
print $langs->trans("Payment");
print '</a>';*/
print $paymenttmp->getNomUrl(1);
} elseif ($links[$key]['type'] == 'payment_supplier') {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
@ -343,9 +348,9 @@ if ($result)
$paymenttmp->fetch($links[$key]['url_id']);
$paymenttmp->ref = $langs->trans("Payment").' '.$paymenttmp->ref;
/*print '<a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$links[$key]['url_id'].'">';
print img_object($langs->trans('Payment'),'payment').' ';
print $langs->trans("Payment");
print '</a>';*/
print img_object($langs->trans('Payment'),'payment').' ';
print $langs->trans("Payment");
print '</a>';*/
print $paymenttmp->getNomUrl(1);
} elseif ($links[$key]['type'] == 'company') {
$societe = new Societe($db);
@ -356,22 +361,19 @@ if ($result)
print img_object($langs->trans('SocialContribution'), 'bill').' ';
print $langs->trans("SocialContribution").($links[$key]['label'] ? ' - '.$links[$key]['label'] : '');
print '</a>';
}
elseif ($links[$key]['type'] == 'vat') {
} elseif ($links[$key]['type'] == 'vat') {
print '<a href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$links[$key]['url_id'].'">';
print img_object($langs->trans('VATDeclaration'), 'bill').' ';
print $langs->trans("VATDeclaration").($links[$key]['label'] ? '&nbsp;'.$links[$key]['label'] : '');
print '</a>';
}
elseif ($links[$key]['type'] == 'payment_sc') {
} elseif ($links[$key]['type'] == 'payment_sc') {
print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$links[$key]['url_id'].'">';
print img_object($langs->trans('Payment'), 'payment').' ';
print $langs->trans("SocialContributionPayment");
print '</a>';
}
elseif ($links[$key]['type'] == 'payment_vat') {
print '<a href="'.DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$links[$key]['url_id'].'">';
print img_object($langs->trans('VATPayment'), 'payment').' ';
} elseif ($links[$key]['type'] == 'payment_vat') {
print '<a href="'.DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$links[$key]['url_id'].'">';
print img_object($langs->trans('VATPayment'), 'payment').' ';
print $langs->trans("VATPayment");
print '</a>';
} elseif ($links[$key]['type'] == 'payment_salary') {
@ -431,13 +433,11 @@ if ($result)
print "<tr><td>".$langs->trans("Type")." / ".$langs->trans("Numero");
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
print "</td>";
if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
{
if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
print '<td>';
$form->select_types_paiements($objp->fk_type, "value", '', 2);
print '<input type="text" class="flat" name="num_chq" value="'.(empty($objp->num_chq) ? '' : $objp->num_chq).'">';
if ($objp->receiptid)
{
if ($objp->receiptid) {
include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
$receipt = new RemiseCheque($db);
$receipt->fetch($objp->receiptid);
@ -453,8 +453,7 @@ if ($result)
print "<tr><td>".$langs->trans("CheckTransmitter");
print ' <em>('.$langs->trans("ChequeMaker").')</em>';
print "</td>";
if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
{
if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
print '<td>';
print '<input type="text" class="flat minwidth200" name="emetteur" value="'.(empty($objp->emetteur) ? '' : stripslashes($objp->emetteur)).'">';
print '</td>';
@ -467,8 +466,7 @@ if ($result)
print "<tr><td>".$langs->trans("Bank");
print ' <em>('.$langs->trans("ChequeBank").')</em>';
print "</td>";
if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
{
if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
print '<td>';
print '<input type="text" class="flat minwidth200" name="banque" value="'.(empty($objp->banque) ? '' : $objp->banque).'">';
print '</td>';
@ -479,12 +477,10 @@ if ($result)
// Date ope
print '<tr><td>'.$langs->trans("DateOperation").'</td>';
if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
{
if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
print '<td>';
print $form->selectDate($db->jdate($objp->do), 'dateo', '', '', '', 'update', 1, 0, $objp->rappro);
if (!$objp->rappro)
{
if (!$objp->rappro) {
print ' &nbsp; ';
print '<a href="'.$_SERVER['PHP_SELF'].'?action=doprev&amp;id='.$id.'&amp;rowid='.$objp->rowid.'">';
print img_edit_remove()."</a> ";
@ -501,12 +497,10 @@ if ($result)
// Value date
print "<tr><td>".$langs->trans("DateValue")."</td>";
if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
{
if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
print '<td>';
print $form->selectDate($db->jdate($objp->dv), 'datev', '', '', '', 'update', 1, 0, $objp->rappro);
if (!$objp->rappro)
{
if (!$objp->rappro) {
print ' &nbsp; ';
print '<a href="'.$_SERVER['PHP_SELF'].'?action=dvprev&amp;id='.$id.'&amp;rowid='.$objp->rowid.'">';
print img_edit_remove()."</a> ";
@ -523,12 +517,10 @@ if ($result)
// Description
print "<tr><td>".$langs->trans("Label")."</td>";
if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
{
if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
print '<td>';
print '<input name="label" class="flat minwidth300" '.($objp->rappro ? ' disabled' : '').' value="';
if (preg_match('/^\((.*)\)$/i', $objp->label, $reg))
{
if (preg_match('/^\((.*)\)$/i', $objp->label, $reg)) {
// Label generique car entre parentheses. On l'affiche en le traduisant
print $langs->trans($reg[1]);
} else {
@ -538,8 +530,7 @@ if ($result)
print '</td>';
} else {
print '<td>';
if (preg_match('/^\((.*)\)$/i', $objp->label, $reg))
{
if (preg_match('/^\((.*)\)$/i', $objp->label, $reg)) {
// Label generique car entre parentheses. On l'affiche en le traduisant
print $langs->trans($reg[1]);
} else {
@ -551,8 +542,7 @@ if ($result)
// Amount
print "<tr><td>".$langs->trans("Amount")."</td>";
if ($user->rights->banque->modifier)
{
if ($user->rights->banque->modifier) {
print '<td>';
print '<input name="amount" class="flat maxwidth100" '.($objp->rappro ? ' disabled' : '').' value="'.price($objp->amount).'"> '.$langs->trans("Currency".$acct->currency_code);
print '</td>';
@ -564,8 +554,7 @@ if ($result)
print "</tr>";
// Categories
if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
{
if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
$langs->load('categories');
// Bank line
@ -589,8 +578,7 @@ if ($result)
// Releve rappro
if ($acct->canBeConciliated() > 0) // Si compte rapprochable
{
if ($acct->canBeConciliated() > 0) { // Si compte rapprochable
print load_fiche_titre($langs->trans("Reconciliation"), '', 'bank_account');
print '<hr>'."\n";
@ -605,17 +593,17 @@ if ($result)
print '<table class="border centpercent">';
print '<tr><td class="titlefield">'.$langs->trans("Conciliation")."</td>";
if ($user->rights->banque->consolidate)
{
if ($user->rights->banque->consolidate) {
print '<td>';
if ($objp->rappro)
{
if ($objp->rappro) {
print $langs->trans("AccountStatement").' <input name="num_rel_bis" class="flat" value="'.$objp->num_releve.'"'.($objp->rappro ? ' disabled' : '').'>';
print '<input name="num_rel" type="hidden" value="'.$objp->num_releve.'">';
} else {
print $langs->trans("AccountStatement").' <input name="num_rel" class="flat" value="'.$objp->num_releve.'"'.($objp->rappro ? ' disabled' : '').'>';
}
if ($objp->num_releve) print ' &nbsp; (<a href="'.DOL_URL_ROOT.'/compta/bank/releve.php?num='.$objp->num_releve.'&account='.$acct->id.'">'.$langs->trans("AccountStatement").' '.$objp->num_releve.')</a>';
if ($objp->num_releve) {
print ' &nbsp; (<a href="'.DOL_URL_ROOT.'/compta/bank/releve.php?num='.$objp->num_releve.'&account='.$acct->id.'">'.$langs->trans("AccountStatement").' '.$objp->num_releve.')</a>';
}
print '</td>';
} else {
print '<td>'.$objp->num_releve.'&nbsp;</td>';
@ -623,8 +611,7 @@ if ($result)
print '</tr>';
print "<tr><td>".$langs->trans("BankLineConciliated")."</td>";
if ($user->rights->banque->consolidate)
{
if ($user->rights->banque->consolidate) {
print '<td>';
print '<input type="checkbox" name="reconciled" class="flat" '.(GETPOSTISSET("reconciled") ? (GETPOST("reconciled") ? ' checked="checked"' : '') : ($objp->rappro ? ' checked="checked"' : '')).'">';
print '</td>';
@ -639,8 +626,7 @@ if ($result)
print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Update").'">';
if ($backtopage)
{
if ($backtopage) {
print ' &nbsp; ';
print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
}
@ -651,7 +637,9 @@ if ($result)
}
$db->free($result);
} else dol_print_error($db);
} else {
dol_print_error($db);
}
// End of page
llxFooter();

View File

@ -32,9 +32,15 @@ require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
if (!empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
if (!empty($conf->accounting->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
}
if (!empty($conf->accounting->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
}
if (!empty($conf->categorie->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
}
// Load translation files required by the page
$langs->loadLangs(array('banks', 'categories', 'accountancy', 'compta'));
@ -52,15 +58,20 @@ $search_number = GETPOST('search_number', 'alpha');
$search_status = GETPOST('search_status') ?GETPOST('search_status', 'alpha') : 'opened'; // 'all' or ''='opened'
$optioncss = GETPOST('optioncss', 'alpha');
if (!empty($conf->categorie->enabled))
{
if (!empty($conf->categorie->enabled)) {
$search_category_list = GETPOST("search_category_".Categorie::TYPE_ACCOUNT."_list", "array");
}
// Security check
if ($user->socid) $socid = $user->socid;
if (!empty($user->rights->accounting->chartofaccount)) $allowed = 1; // Dictionary with list of banks accounting account allowed to manager of chart account
if (!$allowed) $result = restrictedArea($user, 'banque');
if ($user->socid) {
$socid = $user->socid;
}
if (!empty($user->rights->accounting->chartofaccount)) {
$allowed = 1; // Dictionary with list of banks accounting account allowed to manager of chart account
}
if (!$allowed) {
$result = restrictedArea($user, 'banque');
}
$diroutputmassaction = $conf->bank->dir_output.'/temp/massgeneration/'.$user->id;
@ -68,12 +79,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortfield) $sortfield = 'b.label';
if (!$sortorder) $sortorder = 'ASC';
if (!$sortfield) {
$sortfield = 'b.label';
}
if (!$sortorder) {
$sortorder = 'ASC';
}
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$object = new Account($db);
@ -116,19 +133,24 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
* Actions
*/
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
if (GETPOST('cancel', 'alpha')) {
$action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array('socid'=>$socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
// Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
$search_ref = '';
$search_label = '';
$search_number = '';
@ -157,32 +179,44 @@ $accounts = array();
$sql = "SELECT b.rowid, b.label, b.courant, b.rappro, b.account_number, b.fk_accountancy_journal, b.currency_code, b.datec as date_creation, b.tms as date_update";
// Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
}
}
// Add fields from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as b";
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (b.rowid = ef.fk_object)";
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (b.rowid = ef.fk_object)";
}
if (!empty($conf->categorie->enabled))
{
if (!empty($conf->categorie->enabled)) {
$sql .= Categorie::getFilterJoinQuery(Categorie::TYPE_ACCOUNT, "b.rowid");
}
$sql .= " WHERE b.entity IN (".getEntity('bank_account').")";
if ($search_status == 'opened') $sql .= " AND clos = 0";
if ($search_status == 'closed') $sql .= " AND clos = 1";
if ($search_status == 'opened') {
$sql .= " AND clos = 0";
}
if ($search_status == 'closed') {
$sql .= " AND clos = 1";
}
if (!empty($conf->categorie->enabled))
{
if (!empty($conf->categorie->enabled)) {
$sql .= Categorie::getFilterSelectQuery(Categorie::TYPE_ACCOUNT, "b.rowid", $search_category_list);
}
if ($search_ref != '') $sql .= natural_search('b.ref', $search_ref);
if ($search_label != '') $sql .= natural_search('b.label', $search_label);
if ($search_number != '') $sql .= natural_search('b.number', $search_number);
if ($search_ref != '') {
$sql .= natural_search('b.ref', $search_ref);
}
if ($search_label != '') {
$sql .= natural_search('b.label', $search_label);
}
if ($search_number != '') {
$sql .= natural_search('b.number', $search_number);
}
// Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
// Add where from hooks
@ -194,8 +228,7 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
}
@ -203,18 +236,18 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $db->fetch_object($resql);
$accounts[$objp->rowid] = $objp->courant;
$i++;
}
$db->free($resql);
} else dol_print_error($db);
} else {
dol_print_error($db);
}
@ -226,14 +259,30 @@ llxHeader('', $title, $help_url);
$arrayofselected = is_array($toselect) ? $toselect : array();
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if ($search_ref != '') $param .= '&search_ref='.urlencode($search_ref);
if ($search_label != '') $param .= '&search_label='.urlencode($search_label);
if ($search_number != '') $param .= '&search_number='.urlencode($search_number);
if ($search_status != '') $param .= '&search_status='.urlencode($search_status);
if ($show_files) $param .= '&show_files='.urlencode($show_files);
if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($search_ref != '') {
$param .= '&search_ref='.urlencode($search_ref);
}
if ($search_label != '') {
$param .= '&search_label='.urlencode($search_label);
}
if ($search_number != '') {
$param .= '&search_number='.urlencode($search_number);
}
if ($search_status != '') {
$param .= '&search_status='.urlencode($search_status);
}
if ($show_files) {
$param .= '&show_files='.urlencode($show_files);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
@ -242,16 +291,24 @@ $arrayofmassactions = array(
// 'presend'=>$langs->trans("SendByMail"),
// 'builddoc'=>$langs->trans("PDFMerge"),
);
if ($user->rights->banque->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
if ($user->rights->banque->modifier) $arrayofmassactions['preaffecttag'] = '<span class="fa fa-tag paddingrightonly"></span>'.$langs->trans("AffectTag");
if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) $arrayofmassactions = array();
if ($user->rights->banque->supprimer) {
$arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
}
if ($user->rights->banque->modifier) {
$arrayofmassactions['preaffecttag'] = '<span class="fa fa-tag paddingrightonly"></span>'.$langs->trans("AffectTag");
}
if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
$newcardbutton = dolGetButtonTitle($langs->trans('NewFinancialAccount'), '', 'fa fa-plus-circle', 'card.php?action=create', '', $user->rights->banque->configurer);
// Lines of title fields
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
@ -268,27 +325,29 @@ $objecttmp = new Account($db);
$trackid = 'bank'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($sall)
{
foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
if ($sall) {
foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
}
$moreforfilter = '';
if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire)
{
if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
$moreforfilter .= $form->getFilterBox(Categorie::TYPE_ACCOUNT, $search_category_list);
}
// Bank accounts
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
else $moreforfilter = $hookmanager->resPrint;
if (empty($reshook)) {
$moreforfilter .= $hookmanager->resPrint;
} else {
$moreforfilter = $hookmanager->resPrint;
}
if (!empty($moreforfilter))
{
if (!empty($moreforfilter)) {
print '<div class="liste_titre liste_titre_bydiv centpercent">';
print $moreforfilter;
print '</div>';
@ -303,53 +362,45 @@ print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" :
print '<tr class="liste_titre_filter">';
// Ref
if (!empty($arrayfields['b.ref']['checked']))
{
if (!empty($arrayfields['b.ref']['checked'])) {
print '<td class="liste_titre">';
print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
print '</td>';
}
// Label
if (!empty($arrayfields['b.label']['checked']))
{
if (!empty($arrayfields['b.label']['checked'])) {
print '<td class="liste_titre">';
print '<input class="flat" size="6" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
print '</td>';
}
// Account type
if (!empty($arrayfields['accountype']['checked']))
{
if (!empty($arrayfields['accountype']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Bank number
if (!empty($arrayfields['b.number']['checked']))
{
if (!empty($arrayfields['b.number']['checked'])) {
print '<td class="liste_titre">';
print '<input class="flat" size="6" type="text" name="search_number" value="'.dol_escape_htmltag($search_number).'">';
print '</td>';
}
// Account number
if (!empty($arrayfields['b.account_number']['checked']))
{
if (!empty($arrayfields['b.account_number']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Accountancy journal
if (!empty($arrayfields['b.fk_accountancy_journal']['checked']))
{
if (!empty($arrayfields['b.fk_accountancy_journal']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Transactions to reconcile
if (!empty($arrayfields['toreconcile']['checked']))
{
if (!empty($arrayfields['toreconcile']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Currency
if (!empty($arrayfields['b.currency_code']['checked']))
{
if (!empty($arrayfields['b.currency_code']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
@ -361,20 +412,17 @@ $parameters = array('arrayfields'=>$arrayfields);
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// Date creation
if (!empty($arrayfields['b.datec']['checked']))
{
if (!empty($arrayfields['b.datec']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Date modification
if (!empty($arrayfields['b.tms']['checked']))
{
if (!empty($arrayfields['b.tms']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Status
if (!empty($arrayfields['b.clos']['checked']))
{
if (!empty($arrayfields['b.clos']['checked'])) {
print '<td class="liste_titre center">';
$array = array(
'opened'=>$langs->trans("Opened"),
@ -384,8 +432,7 @@ if (!empty($arrayfields['b.clos']['checked']))
print '</td>';
}
// Balance
if (!empty($arrayfields['balance']['checked']))
{
if (!empty($arrayfields['balance']['checked'])) {
print '<td class="liste_titre"></td>';
}
// Action column
@ -397,33 +444,58 @@ print '</tr>';
// Fields title
print '<tr class="liste_titre">';
if (!empty($arrayfields['b.ref']['checked'])) print_liste_field_titre($arrayfields['b.ref']['label'], $_SERVER["PHP_SELF"], 'b.ref', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['b.label']['checked'])) print_liste_field_titre($arrayfields['b.label']['label'], $_SERVER["PHP_SELF"], 'b.label', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['accountype']['checked'])) print_liste_field_titre($arrayfields['accountype']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['b.number']['checked'])) print_liste_field_titre($arrayfields['b.number']['label'], $_SERVER["PHP_SELF"], 'b.number', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['b.account_number']['checked'])) print_liste_field_titre($arrayfields['b.account_number']['label'], $_SERVER["PHP_SELF"], 'b.account_number', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['b.fk_accountancy_journal']['checked'])) print_liste_field_titre($arrayfields['b.fk_accountancy_journal']['label'], $_SERVER["PHP_SELF"], 'b.fk_accountancy_journal', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['b.currency_code']['checked'])) print_liste_field_titre($arrayfields['b.currency_code']['label'], $_SERVER["PHP_SELF"], 'b.currency_code', '', $param, '', $sortfield, $sortorder, 'center ');
if (!empty($arrayfields['toreconcile']['checked'])) print_liste_field_titre($arrayfields['toreconcile']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
if (!empty($arrayfields['b.ref']['checked'])) {
print_liste_field_titre($arrayfields['b.ref']['label'], $_SERVER["PHP_SELF"], 'b.ref', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['b.label']['checked'])) {
print_liste_field_titre($arrayfields['b.label']['label'], $_SERVER["PHP_SELF"], 'b.label', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['accountype']['checked'])) {
print_liste_field_titre($arrayfields['accountype']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['b.number']['checked'])) {
print_liste_field_titre($arrayfields['b.number']['label'], $_SERVER["PHP_SELF"], 'b.number', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['b.account_number']['checked'])) {
print_liste_field_titre($arrayfields['b.account_number']['label'], $_SERVER["PHP_SELF"], 'b.account_number', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['b.fk_accountancy_journal']['checked'])) {
print_liste_field_titre($arrayfields['b.fk_accountancy_journal']['label'], $_SERVER["PHP_SELF"], 'b.fk_accountancy_journal', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['b.currency_code']['checked'])) {
print_liste_field_titre($arrayfields['b.currency_code']['label'], $_SERVER["PHP_SELF"], 'b.currency_code', '', $param, '', $sortfield, $sortorder, 'center ');
}
if (!empty($arrayfields['toreconcile']['checked'])) {
print_liste_field_titre($arrayfields['toreconcile']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields
$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (!empty($arrayfields['b.datec']['checked'])) print_liste_field_titre($arrayfields['b.datec']['label'], $_SERVER["PHP_SELF"], "b.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
if (!empty($arrayfields['b.tms']['checked'])) print_liste_field_titre($arrayfields['b.tms']['label'], $_SERVER["PHP_SELF"], "b.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
if (!empty($arrayfields['b.clos']['checked'])) print_liste_field_titre($arrayfields['b.clos']['label'], $_SERVER["PHP_SELF"], 'b.clos', '', $param, '', $sortfield, $sortorder, 'center ');
if (!empty($arrayfields['balance']['checked'])) print_liste_field_titre($arrayfields['balance']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
if (!empty($arrayfields['b.datec']['checked'])) {
print_liste_field_titre($arrayfields['b.datec']['label'], $_SERVER["PHP_SELF"], "b.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
}
if (!empty($arrayfields['b.tms']['checked'])) {
print_liste_field_titre($arrayfields['b.tms']['label'], $_SERVER["PHP_SELF"], "b.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
}
if (!empty($arrayfields['b.clos']['checked'])) {
print_liste_field_titre($arrayfields['b.clos']['label'], $_SERVER["PHP_SELF"], 'b.clos', '', $param, '', $sortfield, $sortorder, 'center ');
}
if (!empty($arrayfields['balance']['checked'])) {
print_liste_field_titre($arrayfields['balance']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
}
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
print "</tr>\n";
$totalarray = array(); $found = 0; $i = 0; $lastcurrencycode = '';
foreach ($accounts as $key=>$type)
{
if ($i >= $limit) break;
foreach ($accounts as $key => $type) {
if ($i >= $limit) {
break;
}
$found++;
@ -431,53 +503,53 @@ foreach ($accounts as $key=>$type)
$solde = $objecttmp->solde(1);
if (!empty($lastcurrencycode) && $lastcurrencycode != $objecttmp->currency_code)
{
if (!empty($lastcurrencycode) && $lastcurrencycode != $objecttmp->currency_code) {
$lastcurrencycode = 'various'; // We found several different currencies
}
if ($lastcurrencycode != 'various')
{
if ($lastcurrencycode != 'various') {
$lastcurrencycode = $objecttmp->currency_code;
}
print '<tr class="oddeven">';
// Ref
if (!empty($arrayfields['b.ref']['checked']))
{
if (!empty($arrayfields['b.ref']['checked'])) {
print '<td class="nowrap">'.$objecttmp->getNomUrl(1).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Label
if (!empty($arrayfields['b.label']['checked']))
{
if (!empty($arrayfields['b.label']['checked'])) {
print '<td>'.$objecttmp->label.'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Account type
if (!empty($arrayfields['accountype']['checked']))
{
if (!empty($arrayfields['accountype']['checked'])) {
print '<td>';
print $objecttmp->type_lib[$objecttmp->type];
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Number
if (!empty($arrayfields['b.number']['checked']))
{
if (!empty($arrayfields['b.number']['checked'])) {
print '<td>'.$objecttmp->number.'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Account number
if (!empty($arrayfields['b.account_number']['checked']))
{
if (!empty($arrayfields['b.account_number']['checked'])) {
print '<td>';
if (!empty($conf->accounting->enabled) && !empty($objecttmp->account_number))
{
if (!empty($conf->accounting->enabled) && !empty($objecttmp->account_number)) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch('', $objecttmp->account_number, 1);
print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
@ -485,15 +557,15 @@ foreach ($accounts as $key=>$type)
print $objecttmp->account_number;
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Accountancy journal
if (!empty($arrayfields['b.fk_accountancy_journal']['checked']))
{
if (!empty($arrayfields['b.fk_accountancy_journal']['checked'])) {
print '<td>';
if (!empty($conf->accounting->enabled) && !empty($objecttmp->fk_accountancy_journal))
{
if (!empty($conf->accounting->enabled) && !empty($objecttmp->fk_accountancy_journal)) {
$accountingjournal = new AccountingJournal($db);
$accountingjournal->fetch($objecttmp->fk_accountancy_journal);
print $accountingjournal->getNomUrl(0, 1, 1, '', 1);
@ -501,27 +573,31 @@ foreach ($accounts as $key=>$type)
print '';
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Currency
if (!empty($arrayfields['b.currency_code']['checked']))
{
if (!empty($arrayfields['b.currency_code']['checked'])) {
print '<td class="center">';
print $objecttmp->currency_code;
print $objecttmp->currency_code;
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Transactions to reconcile
if (!empty($arrayfields['toreconcile']['checked']))
{
if (!empty($arrayfields['toreconcile']['checked'])) {
print '<td class="center">';
$conciliate = $objecttmp->canBeConciliated();
if ($conciliate == -2) print '<span class="opacitymedium">'.$langs->trans("CashAccount").'</span>';
elseif ($conciliate == -3) print '<span class="opacitymedium">'.$langs->trans("Closed").'</span>';
elseif (empty($objecttmp->rappro)) {
if ($conciliate == -2) {
print '<span class="opacitymedium">'.$langs->trans("CashAccount").'</span>';
} elseif ($conciliate == -3) {
print '<span class="opacitymedium">'.$langs->trans("Closed").'</span>';
} elseif (empty($objecttmp->rappro)) {
print '<span class="opacitymedium">'.$langs->trans("ConciliationDisabled").'</span>';
} else {
$result = $objecttmp->load_board($user, $objecttmp->id);
@ -542,7 +618,9 @@ foreach ($accounts as $key=>$type)
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Extra fields
@ -558,50 +636,59 @@ foreach ($accounts as $key=>$type)
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objecttmp); // Note that $action and $objecttmpect may have been modified by hook
print $hookmanager->resPrint;
// Date creation
if (!empty($arrayfields['b.datec']['checked']))
{
if (!empty($arrayfields['b.datec']['checked'])) {
print '<td class="center">';
print dol_print_date($objecttmp->date_creation, 'dayhour');
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date modification
if (!empty($arrayfields['b.tms']['checked']))
{
if (!empty($arrayfields['b.tms']['checked'])) {
print '<td class="center">';
print dol_print_date($objecttmp->date_update, 'dayhour');
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Status
if (!empty($arrayfields['b.clos']['checked']))
{
if (!empty($arrayfields['b.clos']['checked'])) {
print '<td class="center">'.$objecttmp->getLibStatut(5).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Balance
if (!empty($arrayfields['balance']['checked']))
{
if (!empty($arrayfields['balance']['checked'])) {
print '<td class="nowraponall right">';
print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?id='.$objecttmp->id.'">'.price($solde, 0, $langs, 1, -1, -1, $objecttmp->currency_code).'</a>';
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'balance';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'balance';
}
$totalarray['val']['balance'] += $solde;
}
// Action column
print '<td class="nowrap center">';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
$selected = 0;
if (in_array($objecttmp->id, $arrayofselected)) $selected = 1;
if (in_array($objecttmp->id, $arrayofselected)) {
$selected = 1;
}
print '<input id="cb'.$objecttmp->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$objecttmp->id.'"'.($selected ? ' checked="checked"' : '').'>';
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
print '</tr>';
@ -611,16 +698,18 @@ foreach ($accounts as $key=>$type)
}
// If no record found
if (!$found)
{
if (!$found) {
$colspan = 1;
foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
foreach ($arrayfields as $key => $val) {
if (!empty($val['checked'])) {
$colspan++;
}
}
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
}
// Show total line
if ($lastcurrencycode != 'various') // If there is several currency, $lastcurrencycode is set to 'various' before
{
if ($lastcurrencycode != 'various') { // If there is several currency, $lastcurrencycode is set to 'various' before
// Show total line
include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
}

View File

@ -61,17 +61,17 @@ $newbankreceipt = GETPOST('newbankreceipt', 'alpha');
// Security check
$fieldid = (!empty($ref) ? $ref : $id);
$fieldname = isset($ref) ? 'ref' : 'rowid';
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', $fieldid, 'bank_account', '', '', $fieldname);
if ($user->rights->banque->consolidate && $action == 'dvnext' && !empty($dvid))
{
if ($user->rights->banque->consolidate && $action == 'dvnext' && !empty($dvid)) {
$al = new AccountLine($db);
$al->datev_next($dvid);
}
if ($user->rights->banque->consolidate && $action == 'dvprev' && !empty($dvid))
{
if ($user->rights->banque->consolidate && $action == 'dvprev' && !empty($dvid)) {
$al = new AccountLine($db);
$al->datev_previous($dvid);
}
@ -82,17 +82,24 @@ $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
$pageplusone = GETPOST("pageplusone", 'int');
if ($pageplusone) $page = $pageplusone - 1;
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if ($pageplusone) {
$page = $pageplusone - 1;
}
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) $sortfield = "s.nom";
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "s.nom";
}
$object = new Account($db);
if ($id > 0 || !empty($ref))
{
if ($id > 0 || !empty($ref)) {
$result = $object->fetch($id, $ref);
$account = $object->id; // Force the search field on id of account
}
@ -104,8 +111,7 @@ $contextpage = 'banktransactionlist'.(empty($object->ref) ? '' : '-'.$object->id
// Define number of receipt to show (current, previous or next one ?)
$found = false;
if ($_GET["rel"] == 'prev')
{
if ($_GET["rel"] == 'prev') {
// Recherche valeur pour num = numero releve precedent
$sql = "SELECT DISTINCT(b.num_releve) as num";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
@ -115,18 +121,15 @@ if ($_GET["rel"] == 'prev')
dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$numrows = $db->num_rows($resql);
if ($numrows > 0)
{
if ($numrows > 0) {
$obj = $db->fetch_object($resql);
$numref = $obj->num;
$found = true;
}
}
} elseif ($_GET["rel"] == 'next')
{
} elseif ($_GET["rel"] == 'next') {
// Recherche valeur pour num = numero releve precedent
$sql = "SELECT DISTINCT(b.num_releve) as num";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
@ -136,11 +139,9 @@ if ($_GET["rel"] == 'prev')
dol_syslog("htdocs/compta/bank/releve.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$numrows = $db->num_rows($resql);
if ($numrows > 0)
{
if ($numrows > 0) {
$obj = $db->fetch_object($resql);
$numref = $obj->num;
$found = true;
@ -161,7 +162,9 @@ $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= ", ".MAIN_DB_PREFIX."bank as b";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bordereau_cheque as bc ON bc.rowid=b.fk_bordereau';
$sql .= " WHERE b.num_releve='".$db->escape($numref)."'";
if (empty($numref)) $sql .= " OR b.num_releve is null";
if (empty($numref)) {
$sql .= " OR b.num_releve is null";
}
$sql .= " AND b.fk_account = ".$object->id;
$sql .= " AND b.fk_account = ba.rowid";
$sql .= $db->order("b.datev, b.datec", "ASC"); // We add date of creation to have correct order when everything is done the same day
@ -174,12 +177,13 @@ $sqlrequestforbankline = $sql;
* Actions
*/
if ($action == 'confirm_editbankreceipt' && !empty($oldbankreceipt) && !empty($newbankreceipt))
{
if ($action == 'confirm_editbankreceipt' && !empty($oldbankreceipt) && !empty($newbankreceipt)) {
// TODO Add a test to check newbankreceipt does not exists yet
$sqlupdate = 'UPDATE '.MAIN_DB_PREFIX.'bank SET num_releve = "'.$db->escape($newbankreceipt).'" WHERE num_releve = "'.$db->escape($oldbankreceipt).'" AND fk_account = '.$id;
$result = $db->query($sqlupdate);
if ($result < 0) dol_print_error($db);
if ($result < 0) {
dol_print_error($db);
}
$action = 'view';
}
@ -209,13 +213,18 @@ $paymentvariousstatic = new PaymentVarious($db);
// Must be before button action
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
if ($id > 0) $param .= '&id='.urlencode($id);
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.$contextpage;
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.$limit;
}
if ($id > 0) {
$param .= '&id='.urlencode($id);
}
if (empty($numref))
{
if (empty($numref)) {
$sortfield = 'numr';
$sortorder = 'DESC';
@ -227,8 +236,7 @@ if (empty($numref))
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
}
@ -236,8 +244,7 @@ if (empty($numref))
$sql .= $db->plimit($conf->liste_limit + 1, $offset);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$numrows = $db->num_rows($result);
$i = 0;
@ -310,18 +317,15 @@ if (empty($numref))
$balancestart = array();
$content = array();
while ($i < min($numrows, $conf->liste_limit))
{
while ($i < min($numrows, $conf->liste_limit)) {
$objp = $db->fetch_object($result);
if (!isset($objp->numr))
{
if (!isset($objp->numr)) {
//
} else {
print '<tr class="oddeven">';
print '<td>';
if ($action != 'editbankreceipt' || $objp->numr != $brref)
{
if ($action != 'editbankreceipt' || $objp->numr != $brref) {
print '<a href="releve.php?num='.$objp->numr.'&account='.$object->id.'">'.$objp->numr.'</a>';
} else {
print '<input type="hidden" name="oldbankreceipt" value="'.$objp->numr.'">';
@ -337,8 +341,7 @@ if (empty($numref))
$sql .= " WHERE b.num_releve < '".$db->escape($objp->numr)."'";
$sql .= " AND b.fk_account = ".$object->id;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
$balancestart[$objp->numr] = $obj->amount;
$db->free($resql);
@ -351,8 +354,7 @@ if (empty($numref))
$sql .= " WHERE b.num_releve = '".$db->escape($objp->numr)."'";
$sql .= " AND b.fk_account = ".$object->id;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
$content[$objp->numr] = $obj->amount;
$db->free($resql);
@ -421,8 +423,7 @@ if (empty($numref))
$sql .= " AND b.fk_account = ".$object->id;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
$total = $obj->amount;
$db->free($resql);
@ -432,8 +433,7 @@ if (empty($numref))
$sql = $sqlrequestforbankline;
$result = $db->query($sql);
if ($result)
{
if ($result) {
$numrows = $db->num_rows($result);
$i = 0;
@ -443,8 +443,7 @@ if (empty($numref))
print '<td class="right"><b>'.price($total).'</b></td><td>&nbsp;</td>';
print "</tr>\n";
while ($i < $numrows)
{
while ($i < $numrows) {
$objp = $db->fetch_object($result);
$total = $total + $objp->amount;
@ -481,8 +480,11 @@ if (empty($numref))
print '<a href="'.DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$objp->rowid.'&amp;account='.$object->id.'">';
$reg = array();
preg_match('/\((.+)\)/i', $objp->label, $reg); // Si texte entoure de parenthese on tente recherche de traduction
if ($reg[1] && $langs->trans($reg[1]) != $reg[1]) print $langs->trans($reg[1]);
else print $objp->label;
if ($reg[1] && $langs->trans($reg[1]) != $reg[1]) {
print $langs->trans($reg[1]);
} else {
print $objp->label;
}
print '</a>';
/*
@ -490,63 +492,56 @@ if (empty($numref))
*/
$newline = 1;
$links = $object->get_url($objp->rowid);
foreach ($links as $key=>$val)
{
if (!$newline) print ' - ';
else print '<br>';
if ($links[$key]['type'] == 'payment')
{
foreach ($links as $key => $val) {
if (!$newline) {
print ' - ';
} else {
print '<br>';
}
if ($links[$key]['type'] == 'payment') {
$paymentstatic->id = $links[$key]['url_id'];
$paymentstatic->ref = $langs->trans("Payment");
print ' '.$paymentstatic->getNomUrl(1);
$newline = 0;
} elseif ($links[$key]['type'] == 'payment_supplier')
{
} elseif ($links[$key]['type'] == 'payment_supplier') {
$paymentsupplierstatic->id = $links[$key]['url_id'];
$paymentsupplierstatic->ref = $langs->trans("Payment");
print ' '.$paymentsupplierstatic->getNomUrl(1);
$newline = 0;
} elseif ($links[$key]['type'] == 'payment_sc')
{
} elseif ($links[$key]['type'] == 'payment_sc') {
print '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$links[$key]['url_id'].'">';
print ' '.img_object($langs->trans('ShowPayment'), 'payment').' ';
print $langs->trans("SocialContributionPayment");
print '</a>';
$newline = 0;
} elseif ($links[$key]['type'] == 'payment_vat')
{
} elseif ($links[$key]['type'] == 'payment_vat') {
$paymentvatstatic->id = $links[$key]['url_id'];
$paymentvatstatic->ref = $langs->trans("Payment");
print ' '.$paymentvatstatic->getNomUrl(1);
} elseif ($links[$key]['type'] == 'payment_salary')
{
} elseif ($links[$key]['type'] == 'payment_salary') {
print '<a href="'.DOL_URL_ROOT.'/salaries/card.php?id='.$links[$key]['url_id'].'">';
print ' '.img_object($langs->trans('ShowPayment'), 'payment').' ';
print $langs->trans("Payment");
print '</a>';
$newline = 0;
} elseif ($links[$key]['type'] == 'payment_donation')
{
} elseif ($links[$key]['type'] == 'payment_donation') {
$paymentdonationstatic->id = $links[$key]['url_id'];
$paymentdonationstatic->ref = $langs->trans("Payment");
print ' '.$paymentdonationstatic->getNomUrl(1);
$newline = 0;
} elseif ($links[$key]['type'] == 'payment_loan')
{
} elseif ($links[$key]['type'] == 'payment_loan') {
$paymentloanstatic->id = $links[$key]['url_id'];
$paymentloanstatic->ref = $langs->trans("Payment");
print ' '.$paymentloanstatic->getNomUrl(1);
$newline = 0;
} elseif ($links[$key]['type'] == 'payment_various')
{
} elseif ($links[$key]['type'] == 'payment_various') {
$paymentvariousstatic->id = $links[$key]['url_id'];
$paymentvariousstatic->ref = $langs->trans("Payment");
print ' '.$paymentvariousstatic->getNomUrl(1);
$newline = 0;
} elseif ($links[$key]['type'] == 'banktransfert') {
// Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail.
if ($objp->amount > 0)
{
if ($objp->amount > 0) {
$banklinestatic->fetch($links[$key]['url_id']);
$bankstatic->id = $banklinestatic->fk_account;
$bankstatic->label = $banklinestatic->bank_account_label;
@ -601,8 +596,7 @@ if (empty($numref))
}
// Categories
if ($ve)
{
if ($ve) {
$sql = "SELECT label";
$sql .= " FROM ".MAIN_DB_PREFIX."bank_categ as ct";
$sql .= ", ".MAIN_DB_PREFIX."bank_class as cl";
@ -611,13 +605,13 @@ if (empty($numref))
$sql .= " AND cl.lineid = ".$objp->rowid;
$resc = $db->query($sql);
if ($resc)
{
if ($resc) {
$numc = $db->num_rows($resc);
$ii = 0;
if ($numc && !$newline) print '<br>';
while ($ii < $numc)
{
if ($numc && !$newline) {
print '<br>';
}
while ($ii < $numc) {
$objc = $db->fetch_object($resc);
print "<br>-&nbsp;<i>".$objc->label."</i>";
$ii++;
@ -629,8 +623,7 @@ if (empty($numref))
print "</td>";
if ($objp->amount < 0)
{
if ($objp->amount < 0) {
$totald = $totald + abs($objp->amount);
print '<td class="nowrap right">'.price($objp->amount * -1)."</td><td>&nbsp;</td>\n";
} else {
@ -640,8 +633,7 @@ if (empty($numref))
print '<td class="nowrap right">'.price(price2num($total, 'MT'))."</td>\n";
if ($user->rights->banque->modifier || $user->rights->banque->consolidate)
{
if ($user->rights->banque->modifier || $user->rights->banque->consolidate) {
print '<td class="center"><a class="editfielda reposition" href="'.DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$objp->rowid.'&account='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?account='.$object->id.'&num='.$numref).'">';
print img_edit();
print "</a></td>";

View File

@ -34,8 +34,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
// Load translation files required by the page
$langs->loadLangs(array("banks", "categories", "multicurrency"));
if (!$user->rights->banque->transfer)
accessforbidden();
if (!$user->rights->banque->transfer) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09');
$error = 0;
@ -47,9 +48,10 @@ $hookmanager->initHooks(array('banktransfer'));
*/
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($action == 'add')
{
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if ($action == 'add') {
$langs->load("errors");
$dateo = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
@ -57,28 +59,23 @@ if ($action == 'add')
$amount = price2num(GETPOST('amount', 'alpha'), 'MT');
$amountto = price2num(GETPOST('amountto', 'alpha'), 'MT');
if (!$label)
{
if (!$label) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Description")), null, 'errors');
}
if (!$amount)
{
if (!$amount) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
}
if (!GETPOST('account_from', 'int'))
{
if (!GETPOST('account_from', 'int')) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("TransferFrom")), null, 'errors');
}
if (!GETPOST('account_to', 'int'))
{
if (!GETPOST('account_to', 'int')) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("TransferTo")), null, 'errors');
}
if (!$error)
{
if (!$error) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$accountfrom = new Account($db);
@ -87,19 +84,16 @@ if ($action == 'add')
$accountto = new Account($db);
$accountto->fetch(GETPOST('account_to', 'int'));
if ($accountto->currency_code == $accountfrom->currency_code)
{
if ($accountto->currency_code == $accountfrom->currency_code) {
$amountto = $amount;
} else {
if (!$amountto)
{
if (!$amountto) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AmountTo")), null, 'errors');
}
}
if (($accountto->id != $accountfrom->id) && empty($error))
{
if (($accountto->id != $accountfrom->id) && empty($error)) {
$db->begin();
$bank_line_id_from = 0;
@ -109,25 +103,39 @@ if ($action == 'add')
// By default, electronic transfert from bank to bank
$typefrom = 'PRE';
$typeto = 'VIR';
if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH)
{
if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH) {
// This is transfer of change
$typefrom = 'LIQ';
$typeto = 'LIQ';
}
if (!$error) $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, price2num(-1 * $amount), '', '', $user);
if (!($bank_line_id_from > 0)) $error++;
if (!$error) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, $amountto, '', '', $user);
if (!($bank_line_id_to > 0)) $error++;
if (!$error) {
$bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, price2num(-1 * $amount), '', '', $user);
}
if (!($bank_line_id_from > 0)) {
$error++;
}
if (!$error) {
$bank_line_id_to = $accountto->addline($dateo, $typeto, $label, $amountto, '', '', $user);
}
if (!($bank_line_id_to > 0)) {
$error++;
}
if (!$error) $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert');
if (!($result > 0)) $error++;
if (!$error) $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.'/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert');
if (!($result > 0)) $error++;
if (!$error) {
$result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert');
}
if (!($result > 0)) {
$error++;
}
if (!$error) {
$result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.'/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert');
}
if (!($result > 0)) {
$error++;
}
if (!$error)
{
if (!$error) {
$mesgs = $langs->trans("TransferFromToDone", '{s1}', '{s2}', $amount, $langs->transnoentitiesnoconv("Currency".$conf->currency));
$mesgs = str_replace('{s1}', '<a href="bankentries_list.php?id='.$accountfrom->id.'&sortfield=b.datev,b.dateo,b.rowid&sortorder=desc">'.$accountfrom->label.'</a>', $mesgs);
$mesgs = str_replace('{s2}', '<a href="bankentries_list.php?id='.$accountto->id.'">'.$accountto->label.'</a>', $mesgs);
@ -220,8 +228,7 @@ $account_to = '';
$label = '';
$amount = '';
if ($error)
{
if ($error) {
$account_from = GETPOST('account_from', 'int');
$account_to = GETPOST('account_to', 'int');
$label = GETPOST('label', 'alpha');

View File

@ -37,12 +37,13 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->loadLangs(array('banks', 'categories', 'bills', 'companies'));
// Security check
if (isset($_GET["account"]) || isset($_GET["ref"]))
{
if (isset($_GET["account"]) || isset($_GET["ref"])) {
$id = isset($_GET["account"]) ? $_GET["account"] : (isset($_GET["ref"]) ? $_GET["ref"] : '');
}
$fieldid = isset($_GET["ref"]) ? 'ref' : 'rowid';
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid);
@ -67,22 +68,18 @@ $socialcontribstatic = new ChargeSociales($db);
$form = new Form($db);
if ($_REQUEST["account"] || $_REQUEST["ref"])
{
if ($vline)
{
if ($_REQUEST["account"] || $_REQUEST["ref"]) {
if ($vline) {
$viewline = $vline;
} else {
$viewline = 20;
}
$object = new Account($db);
if ($_GET["account"])
{
if ($_GET["account"]) {
$result = $object->fetch($_GET["account"]);
}
if ($_GET["ref"])
{
if ($_GET["ref"]) {
$result = $object->fetch(0, $_GET["ref"]);
$_GET["account"] = $object->id;
}
@ -101,8 +98,11 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
print '<br>';
$solde = $object->solde(0);
if ($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)$colspan = 6;
else $colspan = 5;
if ($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED) {
$colspan = 6;
} else {
$colspan = 5;
}
// Show next coming entries
print '<div class="div-table-responsive">';
@ -112,7 +112,9 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("DateDue").'</td>';
print '<td>'.$langs->trans("Description").'</td>';
if ($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)print '<td>'.$langs->trans("Entity").'</td>';
if ($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED) {
print '<td>'.$langs->trans("Entity").'</td>';
}
print '<td>'.$langs->trans("ThirdParty").'</td>';
print '<td class="right">'.$langs->trans("Debit").'</td>';
print '<td class="right">'.$langs->trans("Credit").'</td>';
@ -193,37 +195,33 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
}
// Sort array
if (!$error)
{
if (!$error) {
array_multisort($tab_sqlobjOrder, $tab_sqlobj);
// Apply distinct filter
foreach ($tab_sqlobj as $key=>$value) {
foreach ($tab_sqlobj as $key => $value) {
$tab_sqlobj[$key] = "'".serialize($value)."'";
}
$tab_sqlobj = array_unique($tab_sqlobj);
foreach ($tab_sqlobj as $key=>$value) {
foreach ($tab_sqlobj as $key => $value) {
$tab_sqlobj[$key] = unserialize(trim($value, "'"));
}
$num = count($tab_sqlobj);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$ref = '';
$refcomp = '';
$totalpayment = '';
$obj = array_shift($tab_sqlobj);
if ($obj->family == 'invoice_supplier')
{
if ($obj->family == 'invoice_supplier') {
$showline = 1;
// Uncomment this line to avoid to count suppliers credit note (ff.type = 2)
//$showline=(($obj->total_ttc < 0 && $obj->type != 2) || ($obj->total_ttc > 0 && $obj->type == 2))
if ($showline)
{
if ($showline) {
$ref = $obj->ref;
$facturefournstatic->ref = $ref;
$facturefournstatic->id = $obj->objid;
@ -237,8 +235,7 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
$totalpayment = -1 * $facturefournstatic->getSommePaiement(); // Payment already done
}
}
if ($obj->family == 'invoice')
{
if ($obj->family == 'invoice') {
$facturestatic->ref = $obj->ref;
$facturestatic->id = $obj->objid;
$facturestatic->type = $obj->type;
@ -252,8 +249,7 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
$totalpayment += $facturestatic->getSumDepositsUsed();
$totalpayment += $facturestatic->getSumCreditNotesUsed();
}
if ($obj->family == 'social_contribution')
{
if ($obj->family == 'social_contribution') {
$socialcontribstatic->ref = $obj->ref;
$socialcontribstatic->id = $obj->objid;
$socialcontribstatic->label = $obj->type;
@ -271,17 +267,21 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
}
$total_ttc = $obj->total_ttc;
if ($totalpayment) $total_ttc = $obj->total_ttc - $totalpayment;
if ($totalpayment) {
$total_ttc = $obj->total_ttc - $totalpayment;
}
$solde += $total_ttc;
// We discard lines with a remainder to pay to 0
if (price2num($total_ttc) != 0)
{
if (price2num($total_ttc) != 0) {
// Show line
print '<tr class="oddeven">';
print '<td>';
if ($obj->dlr) print dol_print_date($db->jdate($obj->dlr), "day");
else print $langs->trans("NotDefined");
if ($obj->dlr) {
print dol_print_date($db->jdate($obj->dlr), "day");
} else {
print $langs->trans("NotDefined");
}
print "</td>";
print "<td>".$ref."</td>";
if ($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED) {
@ -293,8 +293,12 @@ if ($_REQUEST["account"] || $_REQUEST["ref"])
}
}
print "<td>".$refcomp."</td>";
if ($obj->total_ttc < 0) { print '<td class="nowrap right">'.price(abs($total_ttc))."</td><td>&nbsp;</td>"; };
if ($obj->total_ttc >= 0) { print '<td>&nbsp;</td><td class="nowrap right">'.price($total_ttc)."</td>"; };
if ($obj->total_ttc < 0) {
print '<td class="nowrap right">'.price(abs($total_ttc))."</td><td>&nbsp;</td>";
};
if ($obj->total_ttc >= 0) {
print '<td>&nbsp;</td><td class="nowrap right">'.price($total_ttc)."</td>";
};
print '<td class="nowrap right">'.price($solde).'</td>';
print "</tr>";
}

View File

@ -60,7 +60,9 @@ if (!empty($conf->accounting->enabled) && !empty($conf->global->ACCOUNTANCY_COMB
// Security check
$socid = GETPOST("socid", "int");
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', '', '', '');
$object = new PaymentVarious($db);
@ -75,36 +77,37 @@ $hookmanager->initHooks(array('variouscard', 'globalcard'));
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook))
{
if (empty($reshook)) {
// Link to a project
if ($action == 'classin' && $user->rights->banque->modifier)
{
if ($action == 'classin' && $user->rights->banque->modifier) {
$object->fetch($id);
$object->setProject(GETPOST('projectid'));
}
if ($cancel)
{
if ($action != 'addlink')
{
if ($cancel) {
if ($action != 'addlink') {
$urltogo = $backtopage ? $backtopage : dol_buildpath('/compta/bank/various_payment/list.php', 1);
header("Location: ".$urltogo);
exit;
}
if ($id > 0 || !empty($ref)) $ret = $object->fetch($id, $ref);
if ($id > 0 || !empty($ref)) {
$ret = $object->fetch($id, $ref);
}
$action = '';
}
if ($action == 'add')
{
if ($action == 'add') {
$error = 0;
$datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int'));
$datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int'));
if (empty($datev)) $datev = $datep;
if (empty($datev)) {
$datev = $datep;
}
$object->ref = ''; // TODO
$object->accountid = GETPOST("accountid", 'int') > 0 ? GETPOST("accountid", "int") : 0;
@ -124,50 +127,42 @@ if (empty($reshook))
$object->sens = GETPOSTINT('sens');
$object->fk_project = GETPOSTINT('fk_project');
if (empty($datep) || empty($datev))
{
if (empty($datep) || empty($datev)) {
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
$error++;
}
if (empty($object->amount))
{
if (empty($object->amount)) {
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
$error++;
}
if (!empty($conf->banque->enabled) && !$object->accountid > 0)
{
if (!empty($conf->banque->enabled) && !$object->accountid > 0) {
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
$error++;
}
if (empty($object->type_payment) || $object->type_payment < 0)
{
if (empty($object->type_payment) || $object->type_payment < 0) {
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
$error++;
}
if (!empty($conf->accounting->enabled) && !$object->accountancy_code)
{
if (!empty($conf->accounting->enabled) && !$object->accountancy_code) {
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
$error++;
}
if ($object->sens < 0)
{
if ($object->sens < 0) {
$langs->load('errors');
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Sens")), null, 'errors');
$error++;
}
if (!$error)
{
if (!$error) {
$db->begin();
$ret = $object->create($user);
if ($ret > 0)
{
if ($ret > 0) {
$db->commit();
$urltogo = ($backtopage ? $backtopage : DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
header("Location: ".$urltogo);
@ -182,26 +177,23 @@ if (empty($reshook))
$action = 'create';
}
if ($action == 'delete')
{
if ($action == 'delete') {
$result = $object->fetch($id);
if ($object->rappro == 0)
{
if ($object->rappro == 0) {
$db->begin();
$ret = $object->delete($user);
if ($ret > 0)
{
if ($object->fk_bank)
{
if ($ret > 0) {
if ($object->fk_bank) {
$accountline = new AccountLine($db);
$result = $accountline->fetch($object->fk_bank);
if ($result > 0) $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
if ($result > 0) {
$result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
}
}
if ($result >= 0)
{
if ($result >= 0) {
$db->commit();
header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
exit;
@ -237,18 +229,18 @@ if (empty($reshook))
}
// Action clone object
if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; }
if ($action == 'confirm_clone' && $confirm != 'yes') {
$action = '';
}
if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->modifier))
{
if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->modifier)) {
$db->begin();
$originalId = $id;
$object->fetch($id);
if ($object->id > 0)
{
if ($object->id > 0) {
$object->id = $object->ref = null;
if (GETPOST('clone_label', 'alphanohtml')) {
@ -259,30 +251,30 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->m
$newdatepayment = dol_mktime(0, 0, 0, GETPOST('clone_date_paymentmonth', 'int'), GETPOST('clone_date_paymentday', 'int'), GETPOST('clone_date_paymentyear', 'int'));
$newdatevalue = dol_mktime(0, 0, 0, GETPOST('clone_date_valuemonth', 'int'), GETPOST('clone_date_valueday', 'int'), GETPOST('clone_date_valueyear', 'int'));
if ($newdatepayment) $object->datep = $newdatepayment;
if ($newdatepayment) {
$object->datep = $newdatepayment;
}
if (!empty($newdatevalue)) {
$object->datev = $newdatevalue;
} else {
$object->datev = $newdatepayment;
}
if (GETPOSTISSET("clone_sens")) {
$object->sens = GETPOST("clone_sens", 'int');
} else {
$object->sens = $object->sens;
}
if (GETPOSTISSET("clone_sens")) {
$object->sens = GETPOST("clone_sens", 'int');
} else {
$object->sens = $object->sens;
}
if (GETPOST("clone_amount", "alpha")) {
$object->amount = price2num(GETPOST("clone_amount", "alpha"));
} else {
$object->amount = price2num($object->amount);
}
if (GETPOST("clone_amount", "alpha")) {
$object->amount = price2num(GETPOST("clone_amount", "alpha"));
} else {
$object->amount = price2num($object->amount);
}
if ($object->check())
{
if ($object->check()) {
$id = $object->create($user);
if ($id > 0)
{
if ($id > 0) {
$db->commit();
$db->close();
@ -314,15 +306,17 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->m
llxHeader("", $langs->trans("VariousPayment"));
$form = new Form($db);
if (!empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db);
if (!empty($conf->accounting->enabled)) {
$formaccounting = new FormAccounting($db);
}
if (!empty($conf->projet->enabled)) {
$formproject = new FormProjets($db);
}
if ($id)
{
if ($id) {
$object = new PaymentVarious($db);
$result = $object->fetch($id);
if ($result <= 0)
{
if ($result <= 0) {
dol_print_error($db);
exit;
}
@ -343,8 +337,7 @@ foreach ($bankcateg->fetchAll() as $bankcategory) {
/* Create mode */
/* */
/* ************************************************************************** */
if ($action == 'create')
{
if ($action == 'create') {
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
@ -381,8 +374,7 @@ if ($action == 'create')
print '</td></tr>';
// Bank
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
print '<tr><td>';
print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
$form->select_comptes($accountid, "accountid", 0, '', 2); // Affiche liste des comptes courant
@ -396,8 +388,7 @@ if ($action == 'create')
print '</td></tr>';
// Number
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
// Number
print '<tr><td><label for="num_payment">'.$langs->trans('Numero');
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
@ -443,8 +434,7 @@ if ($action == 'create')
print '</td></tr>';
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$formproject = new FormProjets($db);
// Associated project
@ -489,26 +479,24 @@ if ($action == 'create')
/* */
/* ************************************************************************** */
if ($id)
{
if ($id) {
$alreadyaccounted = $object->getVentilExportCompta();
$head = various_payment_prepare_head($object);
// Clone confirmation
if ($action === 'clone')
{
$set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp")));
$sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
if ($action === 'clone') {
$set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp")));
$sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
$formquestion = array(
array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1),
array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1),
array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'clone_accountid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes($object->fk_account, "accountid", 0, '', 1, '', 0, 'minwidth200', 1)),
array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)),
array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens") . ' ' . $set_value_help, 'values' => $sensarray, 'default' => $object->sens),
);
array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1),
array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1),
array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'clone_accountid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes($object->fk_account, "accountid", 0, '', 1, '', 0, 'minwidth200', 1)),
array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)),
array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens") . ' ' . $set_value_help, 'values' => $sensarray, 'default' => $object->sens),
);
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 350);
}
@ -517,12 +505,10 @@ if ($id)
$morehtmlref = '<div class="refidno">';
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= $langs->trans('Project').' ';
if ($user->rights->banque->modifier)
{
if ($user->rights->banque->modifier) {
if ($action != 'classify') {
$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
}
@ -572,7 +558,11 @@ if ($id)
print '</td></tr>';
// Debit / Credit
if ($object->sens == '1') $sens = $langs->trans("Credit"); else $sens = $langs->trans("Debit");
if ($object->sens == '1') {
$sens = $langs->trans("Credit");
} else {
$sens = $langs->trans("Debit");
}
print '<tr><td>'.$langs->trans("Sens").'</td><td>'.$sens.'</td></tr>';
print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
@ -581,8 +571,7 @@ if ($id)
print '<tr><td class="nowrap">';
print $langs->trans("AccountAccounting");
print '</td><td>';
if (!empty($conf->accounting->enabled))
{
if (!empty($conf->accounting->enabled)) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch('', $object->accountancy_code, 1);
@ -599,10 +588,8 @@ if ($id)
print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0);
print '</td></tr>';
if (!empty($conf->banque->enabled))
{
if ($object->fk_account > 0)
{
if (!empty($conf->banque->enabled)) {
if ($object->fk_account > 0) {
$bankline = new AccountLine($db);
$bankline->fetch($object->fk_bank);
@ -637,16 +624,13 @@ if ($id)
// Add button modify
// Clone
if ($user->rights->banque->modifier)
{
if ($user->rights->banque->modifier) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.dol_buildpath("/compta/bank/various_payment/card.php", 1).'?id='.$object->id.'&amp;action=clone">'.$langs->trans("ToClone")."</a></div>";
}
// Delete
if (empty($object->rappro))
{
if (!empty($user->rights->banque->modifier))
{
if (empty($object->rappro)) {
if (!empty($user->rights->banque->modifier)) {
if ($alreadyaccounted) {
print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("Accounted").'">'.$langs->trans("Delete").'</a></div>';
} else {

View File

@ -39,7 +39,9 @@ $confirm = GETPOST('confirm', 'alpha');
// Security check
$socid = GETPOST("socid", "int");
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', '', '', '');
// Get parameters
@ -47,12 +49,18 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) $sortfield = "name";
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "name";
}
$object = new PaymentVarious($db);
@ -79,20 +87,17 @@ $title = $langs->trans("VariousPayment").' - '.$langs->trans("Documents");
$help_url = '';
llxHeader("", $title, $help_url);
if ($object->id)
{
if ($object->id) {
$head = various_payment_prepare_head($object);
print dol_get_fiche_head($head, 'documents', $langs->trans("VariousPayment"), -1, $object->picto);
$morehtmlref = '<div class="refidno">';
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= $langs->trans('Project').' : ';
if ($user->rights->banque->modifier && 0)
{
if ($user->rights->banque->modifier && 0) {
if ($action != 'classify') {
$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
}
@ -128,8 +133,7 @@ if ($object->id)
// Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0;
foreach ($filearray as $key => $file)
{
foreach ($filearray as $key => $file) {
$totalsize += $file['size'];
}

View File

@ -35,7 +35,9 @@ $action = GETPOST('action', 'aZ09');
// Security check
$socid = GETPOST("socid", "int");
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', '', '', '');
/*
@ -55,12 +57,10 @@ print dol_get_fiche_head($head, 'info', $langs->trans("VariousPayment"), -1, $ob
$morehtmlref = '<div class="refidno">';
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= $langs->trans('Project').' : ';
if ($user->rights->banque->modifier && 0)
{
if ($user->rights->banque->modifier && 0) {
if ($action != 'classify') {
$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
}

View File

@ -37,7 +37,9 @@ $langs->loadLangs(array("compta", "banks", "bills", "accountancy"));
// Security check
$socid = GETPOST("socid", "int");
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', '', '', '');
$optioncss = GETPOST('optioncss', 'alpha');
@ -55,41 +57,58 @@ $search_amount_cred = GETPOST('search_amount_cred', 'alpha');
$search_bank_account = GETPOST('search_account', 'int');
$search_bank_entry = GETPOST('search_bank_entry', 'int');
$search_accountancy_account = GETPOST("search_accountancy_account");
if ($search_accountancy_account == - 1) $search_accountancy_account = '';
if ($search_accountancy_account == - 1) {
$search_accountancy_account = '';
}
$search_accountancy_subledger = GETPOST("search_accountancy_subledger");
if ($search_accountancy_subledger == - 1) $search_accountancy_subledger = '';
if (empty($search_datep_start)) $search_datep_start = GETPOST("search_datep_start", 'int');
if (empty($search_datep_end)) $search_datep_end = GETPOST("search_datep_end", 'int');
if (empty($search_datev_start)) $search_datev_start = GETPOST("search_datev_start", 'int');
if (empty($search_datev_end)) $search_datev_end = GETPOST("search_datev_end", 'int');
if ($search_accountancy_subledger == - 1) {
$search_accountancy_subledger = '';
}
if (empty($search_datep_start)) {
$search_datep_start = GETPOST("search_datep_start", 'int');
}
if (empty($search_datep_end)) {
$search_datep_end = GETPOST("search_datep_end", 'int');
}
if (empty($search_datev_start)) {
$search_datev_start = GETPOST("search_datev_start", 'int');
}
if (empty($search_datev_end)) {
$search_datev_end = GETPOST("search_datev_end", 'int');
}
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortfield) $sortfield = "v.datep,v.rowid";
if (!$sortorder) $sortorder = "DESC,DESC";
if (!$sortfield) {
$sortfield = "v.datep,v.rowid";
}
if (!$sortorder) {
$sortorder = "DESC,DESC";
}
$filtre = GETPOST("filtre", 'alpha');
if (!GETPOST('typeid'))
{
if (!GETPOST('typeid')) {
$newfiltre = str_replace('filtre=', '', $filtre);
$filterarray = explode('-', $newfiltre);
foreach ($filterarray as $val)
{
foreach ($filterarray as $val) {
$part = explode(':', $val);
if ($part[0] == 'v.fk_typepayment') $typeid = $part[1];
if ($part[0] == 'v.fk_typepayment') {
$typeid = $part[1];
}
}
} else {
$typeid = GETPOST('typeid');
}
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
$search_ref = '';
$search_label = '';
$search_datep_start = '';
@ -160,7 +179,9 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
// Selection of new fields
@ -172,13 +193,27 @@ if (empty($reshook)) {
*/
$form = new Form($db);
if ($arrayfields['account']['checked'] || $arrayfields['subledger']['checked']) $formaccounting = new FormAccounting($db);
if ($arrayfields['bank']['checked'] && !empty($conf->accounting->enabled)) $accountingjournal = new AccountingJournal($db);
if ($arrayfields['ref']['checked']) $variousstatic = new PaymentVarious($db);
if ($arrayfields['bank']['checked']) $accountstatic = new Account($db);
if ($arrayfields['project']['checked']) $proj = new Project($db);
if ($arrayfields['entry']['checked']) $bankline = new AccountLine($db);
if ($arrayfields['account']['checked']) $accountingaccount = new AccountingAccount($db);
if ($arrayfields['account']['checked'] || $arrayfields['subledger']['checked']) {
$formaccounting = new FormAccounting($db);
}
if ($arrayfields['bank']['checked'] && !empty($conf->accounting->enabled)) {
$accountingjournal = new AccountingJournal($db);
}
if ($arrayfields['ref']['checked']) {
$variousstatic = new PaymentVarious($db);
}
if ($arrayfields['bank']['checked']) {
$accountstatic = new Account($db);
}
if ($arrayfields['project']['checked']) {
$proj = new Project($db);
}
if ($arrayfields['entry']['checked']) {
$bankline = new AccountLine($db);
}
if ($arrayfields['account']['checked']) {
$accountingaccount = new AccountingAccount($db);
}
$sql = "SELECT v.rowid, v.sens, v.amount, v.label, v.datep as datep, v.datev as datev, v.fk_typepayment as type, v.num_payment, v.fk_bank, v.accountancy_code, v.subledger_account, v.fk_projet as fk_project,";
$sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number as bank_account_number, ba.fk_accountancy_journal as accountancy_journal, ba.label as blabel,";
@ -190,43 +225,68 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.ro
$sql .= " WHERE v.entity IN (".getEntity('payment_various').")";
// Search criteria
if ($search_ref) $sql .= " AND v.rowid=".$db->escape($search_ref);
if ($search_label) $sql .= natural_search(array('v.label'), $search_label);
if ($search_datep_start) $sql .= " AND v.datep >= '".$db->idate($search_datep_start)."'";
if ($search_datep_end) $sql .= " AND v.datep <= '".$db->idate($search_datep_end)."'";
if ($search_datev_start) $sql .= " AND v.datev >= '".$db->idate($search_datev_start)."'";
if ($search_datev_end) $sql .= " AND v.datev <= '".$db->idate($search_datev_end)."'";
if ($search_amount_deb) $sql .= natural_search("v.amount", $search_amount_deb, 1);
if ($search_amount_cred) $sql .= natural_search("v.amount", $search_amount_cred, 1);
if ($search_bank_account > 0) $sql .= " AND b.fk_account=".$db->escape($search_bank_account);
if ($search_bank_entry > 0) $sql .= " AND b.fk_account=".$db->escape($search_bank_account);
if ($search_accountancy_account > 0) $sql .= " AND v.accountancy_code=".$db->escape($search_accountancy_account);
if ($search_accountancy_subledger > 0) $sql .= " AND v.subledger_account=".$db->escape($search_accountancy_subledger);
if ($typeid > 0) $sql .= " AND v.fk_typepayment=".$typeid;
if ($search_ref) {
$sql .= " AND v.rowid=".$db->escape($search_ref);
}
if ($search_label) {
$sql .= natural_search(array('v.label'), $search_label);
}
if ($search_datep_start) {
$sql .= " AND v.datep >= '".$db->idate($search_datep_start)."'";
}
if ($search_datep_end) {
$sql .= " AND v.datep <= '".$db->idate($search_datep_end)."'";
}
if ($search_datev_start) {
$sql .= " AND v.datev >= '".$db->idate($search_datev_start)."'";
}
if ($search_datev_end) {
$sql .= " AND v.datev <= '".$db->idate($search_datev_end)."'";
}
if ($search_amount_deb) {
$sql .= natural_search("v.amount", $search_amount_deb, 1);
}
if ($search_amount_cred) {
$sql .= natural_search("v.amount", $search_amount_cred, 1);
}
if ($search_bank_account > 0) {
$sql .= " AND b.fk_account=".$db->escape($search_bank_account);
}
if ($search_bank_entry > 0) {
$sql .= " AND b.fk_account=".$db->escape($search_bank_account);
}
if ($search_accountancy_account > 0) {
$sql .= " AND v.accountancy_code=".$db->escape($search_accountancy_account);
}
if ($search_accountancy_subledger > 0) {
$sql .= " AND v.subledger_account=".$db->escape($search_accountancy_subledger);
}
if ($typeid > 0) {
$sql .= " AND v.fk_typepayment=".$typeid;
}
if ($filtre) {
$filtre = str_replace(":", "=", $filtre);
$sql .= " AND ".$filtre;
}
if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
if ($search_all) {
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
}
$sql .= $db->order($sortfield, $sortorder);
$totalnboflines = 0;
$result = $db->query($sql);
if ($result)
{
if ($result) {
$totalnboflines = $db->num_rows($result);
}
$sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
// Direct jump if only one record found
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
{
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) {
$obj = $db->fetch_object($result);
$id = $obj->rowid;
header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$id);
@ -240,30 +300,64 @@ if ($result)
$total = 0;
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
if ($search_label) $param .= '&search_label='.urlencode($search_label);
if ($search_datep_start) $param .= '&search_datep_start='.urlencode($search_datep_start);
if ($search_datep_end) $param .= '&search_datep_end='.urlencode($search_datep_end);
if ($search_datev_start) $param .= '&search_datev_start='.urlencode($search_datev_start);
if ($search_datev_end) $param .= '&search_datev_end='.urlencode($search_datev_end);
if ($typeid > 0) $param .= '&typeid='.urlencode($typeid);
if ($search_amount_deb) $param .= '&search_amount_deb='.urlencode($search_amount_deb);
if ($search_amount_cred) $param .= '&search_amount_cred='.urlencode($search_amount_cred);
if ($search_bank_account > 0) $param .= '&search_account='.urlencode($search_bank_account);
if ($search_accountancy_account > 0) $param .= '&search_accountancy_account='.urlencode($search_accountancy_account);
if ($search_accountancy_subledger > 0) $param .= '&search_accountancy_subledger='.urlencode($search_accountancy_subledger);
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($search_ref) {
$param .= '&search_ref='.urlencode($search_ref);
}
if ($search_label) {
$param .= '&search_label='.urlencode($search_label);
}
if ($search_datep_start) {
$param .= '&search_datep_start='.urlencode($search_datep_start);
}
if ($search_datep_end) {
$param .= '&search_datep_end='.urlencode($search_datep_end);
}
if ($search_datev_start) {
$param .= '&search_datev_start='.urlencode($search_datev_start);
}
if ($search_datev_end) {
$param .= '&search_datev_end='.urlencode($search_datev_end);
}
if ($typeid > 0) {
$param .= '&typeid='.urlencode($typeid);
}
if ($search_amount_deb) {
$param .= '&search_amount_deb='.urlencode($search_amount_deb);
}
if ($search_amount_cred) {
$param .= '&search_amount_cred='.urlencode($search_amount_cred);
}
if ($search_bank_account > 0) {
$param .= '&search_account='.urlencode($search_bank_account);
}
if ($search_accountancy_account > 0) {
$param .= '&search_accountancy_account='.urlencode($search_accountancy_account);
}
if ($search_accountancy_subledger > 0) {
$param .= '&search_accountancy_subledger='.urlencode($search_accountancy_subledger);
}
if ($optioncss != '') $param .= '&amp;optioncss='.urlencode($optioncss);
if ($optioncss != '') {
$param .= '&amp;optioncss='.urlencode($optioncss);
}
$url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create';
if (!empty($socid)) $url .= '&socid='.$socid;
if (!empty($socid)) {
$url .= '&socid='.$socid;
}
$newcardbutton = dolGetButtonTitle($langs->trans('MenuNewVariousPayment'), '', 'fa fa-plus-circle', $url, '', $user->rights->banque->modifier);
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
@ -273,9 +367,10 @@ if ($result)
print_barre_liste($langs->trans("MenuVariousPayment"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'object_payment', 0, $newcardbutton, '', $limit, 0, 0, 1);
if ($search_all)
{
foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
if ($search_all) {
foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
}
@ -399,20 +494,46 @@ if ($result)
print '<tr class="liste_titre">';
if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
}
if ($arrayfields['ref']['checked']) print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], 'v.rowid', '', $param, '', $sortfield, $sortorder);
if ($arrayfields['label']['checked']) print_liste_field_titre($arrayfields['label']['label'], $_SERVER["PHP_SELF"], 'v.label', '', $param, '', $sortfield, $sortorder, 'left ');
if ($arrayfields['datep']['checked']) print_liste_field_titre($arrayfields['datep']['label'], $_SERVER["PHP_SELF"], 'v.datep,v.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
if ($arrayfields['datev']['checked']) print_liste_field_titre($arrayfields['datev']['label'], $_SERVER["PHP_SELF"], 'v.datev,v.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
if ($arrayfields['type']['checked']) print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], 'type', '', $param, '', $sortfield, $sortorder, 'left ');
if ($arrayfields['project']['checked']) print_liste_field_titre($arrayfields['project']['label'], $_SERVER["PHP_SELF"], 'fk_project', '', $param, '', $sortfield, $sortorder);
if ($arrayfields['bank']['checked']) print_liste_field_titre($arrayfields['bank']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
if ($arrayfields['entry']['checked']) print_liste_field_titre($arrayfields['entry']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
if ($arrayfields['account']['checked']) print_liste_field_titre($arrayfields['account']['label'], $_SERVER["PHP_SELF"], 'v.accountancy_code', '', $param, '', $sortfield, $sortorder, 'left ');
if ($arrayfields['subledger']['checked']) print_liste_field_titre($arrayfields['subledger']['label'], $_SERVER["PHP_SELF"], 'v.subledger_account', '', $param, '', $sortfield, $sortorder, 'left ');
if ($arrayfields['debit']['checked']) print_liste_field_titre($arrayfields['debit']['label'], $_SERVER["PHP_SELF"], 'v.amount', '', $param, '', $sortfield, $sortorder, 'right ');
if ($arrayfields['credit']['checked']) print_liste_field_titre($arrayfields['credit']['label'], $_SERVER["PHP_SELF"], 'v.amount', '', $param, '', $sortfield, $sortorder, 'right ');
if ($arrayfields['ref']['checked']) {
print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], 'v.rowid', '', $param, '', $sortfield, $sortorder);
}
if ($arrayfields['label']['checked']) {
print_liste_field_titre($arrayfields['label']['label'], $_SERVER["PHP_SELF"], 'v.label', '', $param, '', $sortfield, $sortorder, 'left ');
}
if ($arrayfields['datep']['checked']) {
print_liste_field_titre($arrayfields['datep']['label'], $_SERVER["PHP_SELF"], 'v.datep,v.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
}
if ($arrayfields['datev']['checked']) {
print_liste_field_titre($arrayfields['datev']['label'], $_SERVER["PHP_SELF"], 'v.datev,v.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
}
if ($arrayfields['type']['checked']) {
print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], 'type', '', $param, '', $sortfield, $sortorder, 'left ');
}
if ($arrayfields['project']['checked']) {
print_liste_field_titre($arrayfields['project']['label'], $_SERVER["PHP_SELF"], 'fk_project', '', $param, '', $sortfield, $sortorder);
}
if ($arrayfields['bank']['checked']) {
print_liste_field_titre($arrayfields['bank']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
}
if ($arrayfields['entry']['checked']) {
print_liste_field_titre($arrayfields['entry']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
}
if ($arrayfields['account']['checked']) {
print_liste_field_titre($arrayfields['account']['label'], $_SERVER["PHP_SELF"], 'v.accountancy_code', '', $param, '', $sortfield, $sortorder, 'left ');
}
if ($arrayfields['subledger']['checked']) {
print_liste_field_titre($arrayfields['subledger']['label'], $_SERVER["PHP_SELF"], 'v.subledger_account', '', $param, '', $sortfield, $sortorder, 'left ');
}
if ($arrayfields['debit']['checked']) {
print_liste_field_titre($arrayfields['debit']['label'], $_SERVER["PHP_SELF"], 'v.amount', '', $param, '', $sortfield, $sortorder, 'right ');
}
if ($arrayfields['credit']['checked']) {
print_liste_field_titre($arrayfields['credit']['label'], $_SERVER["PHP_SELF"], 'v.amount', '', $param, '', $sortfield, $sortorder, 'right ');
}
// Fields from hook
$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
@ -424,8 +545,7 @@ if ($result)
$totalarray = array();
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($result);
$variousstatic->id = $obj->rowid;
@ -442,26 +562,34 @@ if ($result)
// Ref
if ($arrayfields['ref']['checked']) {
print '<td>'.$variousstatic->getNomUrl(1)."</td>";
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Label payment
if ($arrayfields['label']['checked']) {
print '<td class="tdoverflowmax150" title="'.$variousstatic->label.'">'.$variousstatic->label."</td>";
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date payment
if ($arrayfields['datep']['checked']) {
print '<td class="center">'.dol_print_date($obj->datep, 'day')."</td>";
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date value
if ($arrayfields['datev']['checked']) {
print '<td class="center">'.dol_print_date($obj->datev, 'day')."</td>";
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Type
@ -473,7 +601,9 @@ if ($result)
}
print $obj->num_payment;
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Project
@ -484,14 +614,15 @@ if ($result)
print $proj->getNomUrl(1);
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Bank account
if ($arrayfields['bank']['checked']) {
print '<td class="nowraponall">';
if ($obj->bid > 0)
{
if ($obj->bid > 0) {
$accountstatic->id = $obj->bid;
$accountstatic->ref = $obj->bref;
$accountstatic->number = $obj->bnumber;
@ -508,14 +639,18 @@ if ($result)
print '&nbsp;';
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Bank entry
if ($arrayfields['entry']['checked']) {
$bankline->fetch($obj->fk_bank);
print '<td>'.$bankline->getNomUrl(1).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Accounting account
@ -523,44 +658,56 @@ if ($result)
$accountingaccount->fetch('', $obj->accountancy_code, 1);
print '<td>'.$accountingaccount->getNomUrl(0, 1, 1, '', 1).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Accounting subledger account
if ($arrayfields['subledger']['checked']) {
print '<td>'.length_accounta($obj->subledger_account).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Debit
if ($arrayfields['debit']['checked']) {
print '<td class="nowrap right">';
if ($obj->sens == 0)
{
if ($obj->sens == 0) {
print price($obj->amount);
$totalarray['val']['total_deb'] += $obj->amount;
}
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'total_deb';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'total_deb';
}
print '</td>';
}
// Credit
if ($arrayfields['credit']['checked']) {
print '<td class="nowrap right">';
if ($obj->sens == 1)
{
if ($obj->sens == 1) {
print price($obj->amount);
$totalarray['val']['total_cred'] += $obj->amount;
}
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'total_cred';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'total_cred';
}
print '</td>';
}
print '<td></td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
print "</tr>";

View File

@ -49,30 +49,38 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortfield) $sortfield = 'rowid';
if (!$sortorder) $sortorder = 'ASC';
if (!$sortfield) {
$sortfield = 'rowid';
}
if (!$sortorder) {
$sortorder = 'ASC';
}
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'thirdpartylist';
if ($contextpage == 'takepos')
{
if ($contextpage == 'takepos') {
$_GET['optioncss'] = 'print';
}
// Security check
if (!$user->rights->cashdesk->run && !$user->rights->takepos->run)
{
if (!$user->rights->cashdesk->run && !$user->rights->takepos->run) {
accessforbidden();
}
$arrayofpaymentmode = array('cash'=>'Cash', 'cheque'=>'Cheque', 'card'=>'CreditCard');
$arrayofposavailable = array();
if (!empty($conf->cashdesk->enabled)) $arrayofposavailable['cashdesk'] = $langs->trans('CashDesk').' (cashdesk)';
if (!empty($conf->takepos->enabled)) $arrayofposavailable['takepos'] = $langs->trans('TakePOS').' (takepos)';
if (!empty($conf->cashdesk->enabled)) {
$arrayofposavailable['cashdesk'] = $langs->trans('CashDesk').' (cashdesk)';
}
if (!empty($conf->takepos->enabled)) {
$arrayofposavailable['takepos'] = $langs->trans('TakePOS').' (takepos)';
}
// TODO Add hook here to allow other POS to add themself
$object = new CashControl($db);
@ -94,18 +102,18 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ
$permissiontoadd = ($user->rights->cashdesk->run || $user->rights->takepos->run);
$permissiontodelete = ($user->rights->cashdesk->run || $user->rights->takepos->run) || ($permissiontoadd && $object->status == 0);
if (empty($backtopage)) $backtopage = dol_buildpath('/compta/cashcontrol/cashcontrol_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
if (empty($backtopage)) {
$backtopage = dol_buildpath('/compta/cashcontrol/cashcontrol_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
}
$backurlforlist = dol_buildpath('/compta/cashcontrol/cashcontrol_list.php', 1);
$triggermodname = 'CACHCONTROL_MODIFY'; // Name of trigger action code to execute when we modify record
if (empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH) && empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH1))
{
if (empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH) && empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH1)) {
setEventMessages($langs->trans("CashDesk")." - ".$langs->trans("NotConfigured"), null, 'errors');
}
if (GETPOST('cancel', 'alpha'))
{
if (GETPOST('cancel', 'alpha')) {
if ($action == 'valid') {
$action = 'view';
} else {
@ -113,8 +121,7 @@ if (GETPOST('cancel', 'alpha'))
}
}
if ($action == "reopen")
{
if ($action == "reopen") {
$result = $object->setStatut($object::STATUS_DRAFT, null, '', 'CASHFENCE_REOPEN');
if ($result < 0) {
dol_print_error($db, $object->error, $object->error);
@ -123,43 +130,35 @@ if ($action == "reopen")
$action = 'view';
}
if ($action == "start")
{
if ($action == "start") {
$error = 0;
if (!GETPOST('posmodule', 'alpha') || GETPOST('posmodule', 'alpha') == '-1')
{
if (!GETPOST('posmodule', 'alpha') || GETPOST('posmodule', 'alpha') == '-1') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Module")), null, 'errors');
$action = 'create';
$error++;
}
if (GETPOST('posnumber', 'alpha') == '')
{
if (GETPOST('posnumber', 'alpha') == '') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CashDesk")), null, 'errors');
$action = 'create';
$error++;
}
if (!GETPOST('closeyear', 'alpha') || GETPOST('closeyear', 'alpha') == '-1')
{
if (!GETPOST('closeyear', 'alpha') || GETPOST('closeyear', 'alpha') == '-1') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Year")), null, 'errors');
$action = 'create';
$error++;
}
} elseif ($action == "add")
{
if (GETPOST('opening', 'alpha') == '')
{
} elseif ($action == "add") {
if (GETPOST('opening', 'alpha') == '') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InitialBankBalance")), null, 'errors');
$action = 'start';
$error++;
}
$error = 0;
foreach ($arrayofpaymentmode as $key=>$val)
{
foreach ($arrayofpaymentmode as $key => $val) {
$object->$key = price2num(GETPOST($key.'_amount', 'alpha'));
}
if (!$error)
{
if (!$error) {
$object->day_close = GETPOST('closeday', 'int');
$object->month_close = GETPOST('closemonth', 'int');
$object->year_close = GETPOST('closeyear', 'int');
@ -172,8 +171,7 @@ if ($action == "start")
$id = $object->create($user);
if ($id > 0)
{
if ($id > 0) {
$db->commit();
$action = "view";
} else {
@ -190,8 +188,7 @@ if ($action == "start")
}
}
if ($action == "valid") // validate = close
{
if ($action == "valid") { // validate = close
$object->fetch($id);
$db->begin();
@ -210,8 +207,7 @@ if ($action == "valid") // validate = close
$result = $object->valid($user);
if ($result <= 0)
{
if ($result <= 0) {
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
} else {
@ -230,27 +226,27 @@ if ($action == "valid") // validate = close
}
// Action to delete
if ($action == 'confirm_delete' && !empty($permissiontodelete))
{
if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
$object->fetch($id);
if (!($object->id > 0))
{
if (!($object->id > 0)) {
dol_print_error('', 'Error, object must be fetched before being deleted');
exit;
}
$result = $object->delete($user);
//var_dump($result);
if ($result > 0)
{
if ($result > 0) {
// Delete OK
setEventMessages("RecordDeleted", null, 'mesgs');
header("Location: ".$backurlforlist);
exit;
} else {
if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
else setEventMessages($object->error, null, 'errors');
if (!empty($object->errors)) {
setEventMessages(null, $object->errors, 'errors');
} else {
setEventMessages($object->error, null, 'errors');
}
}
}
@ -265,8 +261,7 @@ $initialbalanceforterminal = array();
$theoricalamountforterminal = array();
$theoricalnbofinvoiceforterminal = array();
if ($action == "create" || $action == "start" || $action == 'close')
{
if ($action == "create" || $action == "start" || $action == 'close') {
if ($action == 'close') {
$posmodule = $object->posmodule;
$terminalid = $object->posnumber;
@ -275,13 +270,14 @@ if ($action == "create" || $action == "start" || $action == 'close')
$syear = $object->year_close;
$smonth = $object->month_close;
$sday = $object->day_close;
} elseif (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1')
{
} elseif (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1') {
$posmodule = GETPOST('posmodule', 'alpha');
$terminalid = GETPOST('posnumber', 'alpha');
$terminaltouse = $terminalid;
if ($terminaltouse == '1' && $posmodule == 'cashdesk') $terminaltouse = '';
if ($terminaltouse == '1' && $posmodule == 'cashdesk') {
$terminaltouse = '';
}
if ($posmodule == 'cashdesk' && $terminaltouse != '' && $terminaltouse != '1') {
$terminaltouse = '';
@ -290,13 +286,10 @@ if ($action == "create" || $action == "start" || $action == 'close')
}
}
if ($terminalid != '')
{
if ($terminalid != '') {
// Calculate $initialbalanceforterminal for terminal 0
foreach ($arrayofpaymentmode as $key => $val)
{
if ($key != 'cash')
{
foreach ($arrayofpaymentmode as $key => $val) {
if ($key != 'cash') {
$initialbalanceforterminal[$terminalid][$key] = 0;
continue;
}
@ -305,21 +298,28 @@ if ($action == "create" || $action == "start" || $action == 'close')
$vartouse = 'CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse;
$bankid = $conf->global->$vartouse;
if ($bankid > 0)
{
if ($bankid > 0) {
$sql = "SELECT SUM(amount) as total FROM ".MAIN_DB_PREFIX."bank";
$sql .= " WHERE fk_account = ".$bankid;
if ($syear && !$smonth) $sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, 1))."'";
elseif ($syear && $smonth && !$sday) $sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, $smonth))."'";
elseif ($syear && $smonth && $sday) $sql .= " AND dateo < '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."'";
else dol_print_error('', 'Year not defined');
if ($syear && !$smonth) {
$sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, 1))."'";
} elseif ($syear && $smonth && !$sday) {
$sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, $smonth))."'";
} elseif ($syear && $smonth && $sday) {
$sql .= " AND dateo < '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."'";
} else {
dol_print_error('', 'Year not defined');
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj) $initialbalanceforterminal[$terminalid][$key] = $obj->total;
} else dol_print_error($db);
if ($obj) {
$initialbalanceforterminal[$terminalid][$key] = $obj->total;
}
} else {
dol_print_error($db);
}
} else {
setEventMessages($langs->trans("SetupOfTerminalNotComplete", $terminaltouse), null, 'errors');
$error++;
@ -327,8 +327,7 @@ if ($action == "create" || $action == "start" || $action == 'close')
}
// Calculate $theoricalamountforterminal
foreach ($arrayofpaymentmode as $key => $val)
{
foreach ($arrayofpaymentmode as $key => $val) {
$sql = "SELECT SUM(pf.amount) as total, COUNT(*) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."c_paiement as cp";
$sql .= " WHERE pf.fk_facture = f.rowid AND p.rowid = pf.fk_paiement AND cp.id = p.fk_paiement";
@ -336,30 +335,38 @@ if ($action == "create" || $action == "start" || $action == 'close')
$sql .= " AND f.pos_source = '".$db->escape($terminalid)."'";
$sql .= " AND f.paye = 1";
$sql .= " AND p.entity IN (".getEntity('facture').")";
if ($key == 'cash') $sql .= " AND cp.code = 'LIQ'";
elseif ($key == 'cheque') $sql .= " AND cp.code = 'CHQ'";
elseif ($key == 'card') $sql .= " AND cp.code = 'CB'";
else {
if ($key == 'cash') {
$sql .= " AND cp.code = 'LIQ'";
} elseif ($key == 'cheque') {
$sql .= " AND cp.code = 'CHQ'";
} elseif ($key == 'card') {
$sql .= " AND cp.code = 'CB'";
} else {
dol_print_error('Value for key = '.$key.' not supported');
exit;
}
if ($syear && !$smonth) $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
elseif ($syear && $smonth && !$sday) $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
elseif ($syear && $smonth && $sday) $sql .= " AND datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $smonth, $sday, $syear))."'";
else dol_print_error('', 'Year not defined');
if ($syear && !$smonth) {
$sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
} elseif ($syear && $smonth && !$sday) {
$sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
} elseif ($syear && $smonth && $sday) {
$sql .= " AND datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $smonth, $sday, $syear))."'";
} else {
dol_print_error('', 'Year not defined');
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$theoricalamountforterminal[$terminalid][$key] = $initialbalanceforterminal[$terminalid][$key];
$obj = $db->fetch_object($resql);
if ($obj)
{
if ($obj) {
$theoricalamountforterminal[$terminalid][$key] = price2num($theoricalamountforterminal[$terminalid][$key] + $obj->total);
$theoricalnbofinvoiceforterminal[$terminalid][$key] = $obj->nb;
}
} else dol_print_error($db);
} else {
dol_print_error($db);
}
}
}
@ -371,12 +378,12 @@ if ($action == "create" || $action == "start" || $action == 'close')
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
if ($contextpage == 'takepos') print '<input type="hidden" name="contextpage" value="takepos">';
if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1')
{
if ($contextpage == 'takepos') {
print '<input type="hidden" name="contextpage" value="takepos">';
}
if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') {
print '<input type="hidden" name="action" value="add">';
} elseif ($action == 'close')
{
} elseif ($action == 'close') {
print '<input type="hidden" name="action" value="valid">';
print '<input type="hidden" name="id" value="'.$id.'">';
} else {
@ -407,8 +414,7 @@ if ($action == "create" || $action == "start" || $action == 'close')
$array[$i] = $i;
}
$selectedposnumber = 0; $showempty = 1;
if ($conf->global->TAKEPOS_NUM_TERMINALS == '1')
{
if ($conf->global->TAKEPOS_NUM_TERMINALS == '1') {
$selectedposnumber = 1; $showempty = 0;
}
print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty);
@ -417,8 +423,7 @@ if ($action == "create" || $action == "start" || $action == 'close')
// Year
print '<td>';
$retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'year" name="'.$prefix.'year">';
for ($year = $syear - 10; $year < $syear + 10; $year++)
{
for ($year = $syear - 10; $year < $syear + 10; $year++) {
$retstring .= '<option value="'.$year.'"'.($year == $syear ? ' selected' : '').'>'.$year.'</option>';
}
$retstring .= "</select>\n";
@ -428,8 +433,7 @@ if ($action == "create" || $action == "start" || $action == 'close')
print '<td>';
$retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'month" name="'.$prefix.'month">';
$retstring .= '<option value="0"></option>';
for ($month = 1; $month <= 12; $month++)
{
for ($month = 1; $month <= 12; $month++) {
$retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>';
$retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
$retstring .= "</option>";
@ -441,8 +445,7 @@ if ($action == "create" || $action == "start" || $action == 'close')
print '<td>';
$retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50imp" id="'.$prefix.'day" name="'.$prefix.'day">';
$retstring .= '<option value="0" selected>&nbsp;</option>';
for ($day = 1; $day <= 31; $day++)
{
for ($day = 1; $day <= 31; $day++) {
$retstring .= '<option value="'.$day.'"'.($day == $sday ? ' selected' : '').'>'.$day.'</option>';
}
$retstring .= "</select>";
@ -450,8 +453,7 @@ if ($action == "create" || $action == "start" || $action == 'close')
print '</td>';
// Button Start
print '<td>';
if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1')
{
if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') {
print '';
} else {
print '<input type="submit" name="add" class="button" value="'.$langs->trans("Start").'">';
@ -461,8 +463,7 @@ if ($action == "create" || $action == "start" || $action == 'close')
print '</div>';
// Table to see/enter balance
if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close')
{
if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
$posmodule = GETPOST('posmodule', 'alpha');
$terminalid = GETPOST('posnumber', 'alpha');
@ -511,10 +512,10 @@ if ($action == "create" || $action == "start" || $action == 'close')
$i = 0;
foreach ($arrayofpaymentmode as $key => $val)
{
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
print $theoricalnbofinvoiceforterminal[$terminalid][$key];
print '</td>';
$i++;
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
print $theoricalnbofinvoiceforterminal[$terminalid][$key];
print '</td>';
$i++;
}
// Save
print '<td align="center"></td>';
@ -545,13 +546,16 @@ if ($action == "create" || $action == "start" || $action == 'close')
// Initial amount
print '<td class="center">';
print '<input ';
if ($action == 'close') print 'disabled '; // To close cash user can't set opening cash
if ($action == 'close') {
print 'disabled '; // To close cash user can't set opening cash
}
print 'name="opening" type="text" class="maxwidth100 center" value="';
if ($action == 'close')
{
if ($action == 'close') {
$object->fetch($id);
print $object->opening;
} else print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
} else {
print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
}
print '">';
print '</td>';
// Amount per payment type
@ -568,8 +572,11 @@ if ($action == "create" || $action == "start" || $action == 'close')
// Save
print '<td class="center">';
print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
if ($action == 'start') print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
elseif ($action == 'close') print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Validate").'">';
if ($action == 'start') {
print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
} elseif ($action == 'close') {
print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Validate").'">';
}
print '</td>';
print '</tr>';
@ -581,8 +588,7 @@ if ($action == "create" || $action == "start" || $action == 'close')
}
}
if (empty($action) || $action == "view" || $action == "close")
{
if (empty($action) || $action == "view" || $action == "close") {
$result = $object->fetch($id);
llxHeader('', $langs->trans("CashControl"));
@ -648,8 +654,7 @@ if (empty($action) || $action == "view" || $action == "close")
print '<tr><td valign="middle">'.$langs->trans("InitialBankBalance").' - '.$langs->trans("Cash").'</td><td>';
print price($object->opening, 0, $langs, 1, -1, -1, $conf->currency);
print "</td></tr>";
foreach ($arrayofpaymentmode as $key => $val)
{
foreach ($arrayofpaymentmode as $key => $val) {
print '<tr><td valign="middle">'.$langs->trans($val).'</td><td>';
print price($object->$key, 0, $langs, 1, -1, -1, $conf->currency);
print "</td></tr>";
@ -667,8 +672,7 @@ if (empty($action) || $action == "view" || $action == "close")
print '<div class="inline-block divButAction"><a target="_blank" class="butAction" href="report.php?id='.$id.'">'.$langs->trans('PrintTicket').'</a></div>';
if ($object->status == CashControl::STATUS_DRAFT)
{
if ($object->status == CashControl::STATUS_DRAFT) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=close&amp;contextpage='.$contextpage.'">'.$langs->trans('Close').'</a></div>';
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=confirm_delete">'.$langs->trans('Delete').'</a></div>';
@ -678,16 +682,18 @@ if (empty($action) || $action == "view" || $action == "close")
print '</div>';
if ($contextpage != 'takepos') print '<center><iframe src="report.php?id='.$id.'" width="60%" height="800"></iframe></center>';
if ($contextpage != 'takepos') {
print '<center><iframe src="report.php?id='.$id.'" width="60%" height="800"></iframe></center>';
}
} else {
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="formclose">';
print '<input type="hidden" name="token" value="'.newToken().'">';
if ($contextpage == 'takepos') print '<input type="hidden" name="contextpage" value="takepos">';
if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1')
{
if ($contextpage == 'takepos') {
print '<input type="hidden" name="contextpage" value="takepos">';
}
if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') {
print '<input type="hidden" name="action" value="add">';
} elseif ($action == 'close')
{
} elseif ($action == 'close') {
print '<input type="hidden" name="action" value="valid">';
print '<input type="hidden" name="id" value="'.$id.'">';
} else {
@ -695,59 +701,58 @@ if (empty($action) || $action == "view" || $action == "close")
}
/*
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Module").'</td>';
print '<td>'.$langs->trans("Terminal").'</td>';
print '<td>'.$langs->trans("Year").'</td>';
print '<td>'.$langs->trans("Month").'</td>';
print '<td>'.$langs->trans("Day").'</td>';
print '<td></td>';
print "</tr>\n";
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Module").'</td>';
print '<td>'.$langs->trans("Terminal").'</td>';
print '<td>'.$langs->trans("Year").'</td>';
print '<td>'.$langs->trans("Month").'</td>';
print '<td>'.$langs->trans("Day").'</td>';
print '<td></td>';
print "</tr>\n";
$disabled = 1;
$prefix = 'close';
$disabled = 1;
$prefix = 'close';
print '<tr class="oddeven">';
print '<td>'.$form->selectarray('posmodulebis', $arrayofposavailable, $object->posmodule, (count($arrayofposavailable) > 1 ? 1 : 0), 0, 0, '', 0, 0, $disabled).'</td>';
print '<input type="hidden" name="posmodule" value="'.$object->posmodule.'">';
print '<td>';
print '<tr class="oddeven">';
print '<td>'.$form->selectarray('posmodulebis', $arrayofposavailable, $object->posmodule, (count($arrayofposavailable) > 1 ? 1 : 0), 0, 0, '', 0, 0, $disabled).'</td>';
print '<input type="hidden" name="posmodule" value="'.$object->posmodule.'">';
print '<td>';
$array = array();
$numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
for($i = 1; $i <= $numterminals; $i++) {
$array[$i] = $i;
}
$selectedposnumber = $object->posnumber; $showempty = 1;
//print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty, 0, 0, '', 0, 0, $disabled);
print '<input name="posnumberbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->posnumber.'">';
print '<input type="hidden" name="posnumber" value="'.$object->posmodule.'">';
print '</td>';
// Year
print '<td>';
print '<input name="yearbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->year_close.'">';
print '<input type="hidden" name="year_close" value="'.$object->year_close.'">';
print '</td>';
// Month
print '<td>';
print '<input name="monthbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->month_close.'">';
print '<input type="hidden" name="month_close" value="'.$object->month_close.'">';
print '</td>';
// Day
print '<td>';
print '<input name="daybis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->date_close.'">';
print '<input type="hidden" name="day_close" value="'.$object->date_close.'">';
print '</td>';
$array = array();
$numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
for($i = 1; $i <= $numterminals; $i++) {
$array[$i] = $i;
}
$selectedposnumber = $object->posnumber; $showempty = 1;
//print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty, 0, 0, '', 0, 0, $disabled);
print '<input name="posnumberbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->posnumber.'">';
print '<input type="hidden" name="posnumber" value="'.$object->posmodule.'">';
print '</td>';
// Year
print '<td>';
print '<input name="yearbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->year_close.'">';
print '<input type="hidden" name="year_close" value="'.$object->year_close.'">';
print '</td>';
// Month
print '<td>';
print '<input name="monthbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->month_close.'">';
print '<input type="hidden" name="month_close" value="'.$object->month_close.'">';
print '</td>';
// Day
print '<td>';
print '<input name="daybis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->date_close.'">';
print '<input type="hidden" name="day_close" value="'.$object->date_close.'">';
print '</td>';
print '<td></td>';
print '</table>';
print '</div>';
*/
print '</table>';
print '</div>';
*/
// Table to see/enter balance
if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close')
{
if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
$posmodule = $object->posmodule;
$terminalid = $object->posnumber;
@ -774,8 +779,7 @@ if (empty($action) || $action == "view" || $action == "close")
//print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
print '</td>';
$i = 0;
foreach ($arrayofpaymentmode as $key => $val)
{
foreach ($arrayofpaymentmode as $key => $val) {
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
//print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
print '</td>';
@ -791,8 +795,7 @@ if (empty($action) || $action == "view" || $action == "close")
print '</td>';
// Amount per payment type
$i = 0;
foreach ($arrayofpaymentmode as $key => $val)
{
foreach ($arrayofpaymentmode as $key => $val) {
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
print $theoricalnbofinvoiceforterminal[$terminalid][$key];
print '</td>';
@ -810,8 +813,7 @@ if (empty($action) || $action == "view" || $action == "close")
print '</td>';
// Amount per payment type
$i = 0;
foreach ($arrayofpaymentmode as $key => $val)
{
foreach ($arrayofpaymentmode as $key => $val) {
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
if ($key == 'cash') {
$deltaforcash = ($object->opening - $initialbalanceforterminal[$terminalid]['cash']);
@ -831,22 +833,26 @@ if (empty($action) || $action == "view" || $action == "close")
// Initial amount
print '<td class="center">';
print '<input ';
if ($action == 'close') print 'disabled '; // To close cash user can't set opening cash
if ($action == 'close') {
print 'disabled '; // To close cash user can't set opening cash
}
print 'name="opening" type="text" class="maxwidth100 center" value="';
if ($action == 'close')
{
if ($action == 'close') {
$object->fetch($id);
print $object->opening;
} else print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
} else {
print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
}
print '">';
print '</td>';
// Amount per payment type
$i = 0;
foreach ($arrayofpaymentmode as $key => $val)
{
foreach ($arrayofpaymentmode as $key => $val) {
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
print '<input ';
if ($action == 'start') print 'disabled '; // To start cash user only can set opening cash
if ($action == 'start') {
print 'disabled '; // To start cash user only can set opening cash
}
print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
print '</td>';
$i++;
@ -854,8 +860,11 @@ if (empty($action) || $action == "view" || $action == "close")
// Save
print '<td class="center">';
print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
if ($action == 'start') print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
elseif ($action == 'close') print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Close").'">';
if ($action == 'start') {
print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
} elseif ($action == 'close') {
print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Close").'">';
}
print '</td>';
print '</tr>';

View File

@ -66,7 +66,9 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
$page = 0;
} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
@ -85,13 +87,16 @@ $extrafields->fetch_name_optionals_label($object->table_element);
$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
// Default sort order (if not yet defined by previous GETPOST)
if (!$sortfield) $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) {
$sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
}
if (!$sortorder) {
$sortorder = "ASC";
}
// Security check
$socid = 0;
if ($user->socid > 0) // Protection if external user
{
if ($user->socid > 0) { // Protection if external user
//$socid = $user->socid;
accessforbidden();
}
@ -100,24 +105,27 @@ if ($user->socid > 0) // Protection if external user
// Initialize array of search criterias
$search_all = GETPOST("search_all", 'alpha');
$search = array();
foreach ($object->fields as $key => $val)
{
if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
foreach ($object->fields as $key => $val) {
if (GETPOST('search_'.$key, 'alpha')) {
$search[$key] = GETPOST('search_'.$key, 'alpha');
}
}
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array();
foreach ($object->fields as $key => $val)
{
if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
foreach ($object->fields as $key => $val) {
if ($val['searchall']) {
$fieldstosearchall['t.'.$key] = $val['label'];
}
}
// Definition of fields for list
$arrayfields = array();
foreach ($object->fields as $key => $val)
{
foreach ($object->fields as $key => $val) {
// If $val['visible']==0, then we never show the field
if (!empty($val['visible'])) $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>$val['enabled'], 'position'=>$val['position']);
if (!empty($val['visible'])) {
$arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>$val['enabled'], 'position'=>$val['position']);
}
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
@ -131,31 +139,33 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
* Actions
*/
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
if (GETPOST('cancel', 'alpha')) {
$action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook))
{
if (empty($reshook)) {
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
{
foreach ($object->fields as $key => $val)
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
foreach ($object->fields as $key => $val) {
$search[$key] = '';
}
$toselect = '';
$search_array_options = array();
}
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha'))
{
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
}
@ -187,14 +197,14 @@ $title = $langs->trans('CashControl');
// Build and execute select
// --------------------------------------------------------------------
$sql = 'SELECT ';
foreach ($object->fields as $key => $val)
{
foreach ($object->fields as $key => $val) {
$sql .= 't.'.$key.', ';
}
// Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label']))
{
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
}
}
// Add fields from hooks
$parameters = array();
@ -202,16 +212,26 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $obje
$sql .= $hookmanager->resPrint;
$sql = preg_replace('/, $/', '', $sql);
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
else $sql .= " WHERE 1 = 1";
foreach ($search as $key => $val)
{
if ($key == 'status' && $search[$key] == -1) continue;
$mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
if ($search[$key] != '') $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
}
if ($object->ismultientitymanaged == 1) {
$sql .= " WHERE t.entity IN (".getEntity($object->element).")";
} else {
$sql .= " WHERE 1 = 1";
}
foreach ($search as $key => $val) {
if ($key == 'status' && $search[$key] == -1) {
continue;
}
$mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
if ($search[$key] != '') {
$sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
}
}
if ($search_all) {
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
}
if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
// Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
// Add where from hooks
@ -239,26 +259,22 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$resql = $db->query($sql);
$nbtotalofrecords = $db->num_rows($resql);
if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
$page = 0;
$offset = 0;
}
}
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
{
if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
$num = $nbtotalofrecords;
} else {
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
exit;
}
@ -267,8 +283,7 @@ if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
}
// Direct jump if only one record found
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
{
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) {
$obj = $db->fetch_object($resql);
$id = $obj->rowid;
header("Location: ".dol_buildpath('/compta/cashcontrol/cashcontrol_card.php', 1).'?id='.$id);
@ -299,13 +314,18 @@ jQuery(document).ready(function() {
$arrayofselected = is_array($toselect) ? $toselect : array();
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
foreach ($search as $key => $val)
{
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
foreach ($search as $key => $val) {
$param .= '&search_'.$key.'='.urlencode($search[$key]);
}
if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
@ -315,11 +335,15 @@ $arrayofmassactions = array(
//'builddoc'=>$langs->trans("PDFMerge"),
);
//if ($user->rights->monmodule->delete) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
@ -340,9 +364,10 @@ $objecttmp = new CashControl($db);
$trackid = 'cashfence'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($sall)
{
foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
if ($sall) {
foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
}
@ -353,11 +378,13 @@ $moreforfilter = '';
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
else $moreforfilter = $hookmanager->resPrint;
if (empty($reshook)) {
$moreforfilter .= $hookmanager->resPrint;
} else {
$moreforfilter = $hookmanager->resPrint;
}
if (!empty($moreforfilter))
{
if (!empty($moreforfilter)) {
print '<div class="liste_titre liste_titre_bydiv centpercent">';
print $moreforfilter;
print '</div>';
@ -374,18 +401,24 @@ print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" :
// Fields title search
// --------------------------------------------------------------------
print '<tr class="liste_titre">';
foreach ($object->fields as $key => $val)
{
foreach ($object->fields as $key => $val) {
$cssforfield = (empty($val['css']) ? '' : $val['css']);
if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
if (!empty($arrayfields['t.'.$key]['checked']))
{
if ($key == 'status') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
} elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
$cssforfield .= ($cssforfield ? ' ' : '').'right';
}
if (!empty($arrayfields['t.'.$key]['checked'])) {
print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
else print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
} else {
print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
}
print '</td>';
}
}
@ -407,15 +440,18 @@ print '</tr>'."\n";
// Fields title label
// --------------------------------------------------------------------
print '<tr class="liste_titre">';
foreach ($object->fields as $key => $val)
{
foreach ($object->fields as $key => $val) {
$cssforfield = (empty($val['css']) ? '' : $val['css']);
if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
if (!empty($arrayfields['t.'.$key]['checked']))
{
if ($key == 'status') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
} elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
$cssforfield .= ($cssforfield ? ' ' : '').'right';
}
if (!empty($arrayfields['t.'.$key]['checked'])) {
print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
}
}
@ -431,11 +467,11 @@ print '</tr>'."\n";
// Detect if we need a fetch on each output line
$needToFetchEachLine = 0;
if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0)
{
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
{
if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object
if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
if (preg_match('/\$object/', $val)) {
$needToFetchEachLine++; // There is at least one compute field that use $object
}
}
}
@ -444,42 +480,57 @@ if (is_array($extrafields->attributes[$object->table_element]['computed']) && co
// --------------------------------------------------------------------
$i = 0;
$totalarray = array();
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($resql);
if (empty($obj)) break; // Should not happen
if (empty($obj)) {
break; // Should not happen
}
// Store properties in $object
$object->id = $obj->rowid;
foreach ($object->fields as $key => $val)
{
if (property_exists($obj, $key)) $object->$key = $obj->$key;
foreach ($object->fields as $key => $val) {
if (property_exists($obj, $key)) {
$object->$key = $obj->$key;
}
}
// Show here line of result
print '<tr class="oddeven">';
foreach ($object->fields as $key => $val)
{
foreach ($object->fields as $key => $val) {
$cssforfield = (empty($val['css']) ? '' : $val['css']);
if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif ($key == 'status') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
}
if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
elseif ($key == 'ref') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
if (in_array($val['type'], array('timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
} elseif ($key == 'ref') {
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
}
if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right';
if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') {
$cssforfield .= ($cssforfield ? ' ' : '').'right';
}
if (!empty($arrayfields['t.'.$key]['checked']))
{
if (!empty($arrayfields['t.'.$key]['checked'])) {
print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
if ($key == 'status') print $object->getLibStatut(5);
elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) print $object->showOutputField($val, $key, $db->jdate($obj->$key), '');
else print $object->showOutputField($val, $key, $obj->$key, '');
if ($key == 'status') {
print $object->getLibStatut(5);
} elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
print $object->showOutputField($val, $key, $db->jdate($obj->$key), '');
} else {
print $object->showOutputField($val, $key, $obj->$key, '');
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!empty($val['isameasure']))
{
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
if (!$i) {
$totalarray['nbfield']++;
}
if (!empty($val['isameasure'])) {
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
}
$totalarray['val']['t.'.$key] += $obj->$key;
}
}
@ -492,14 +543,17 @@ while ($i < min($num, $limit))
print $hookmanager->resPrint;
// Action column
print '<td class="nowrap" align="center">';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
$selected = 0;
if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
if (in_array($obj->rowid, $arrayofselected)) {
$selected = 1;
}
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
print '</tr>';
@ -511,10 +565,13 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
// If no record found
if ($num == 0)
{
if ($num == 0) {
$colspan = 1;
foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
foreach ($arrayfields as $key => $val) {
if (!empty($val['checked'])) {
$colspan++;
}
}
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
}
@ -529,10 +586,11 @@ print '</div>'."\n";
print '</form>'."\n";
if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords))
{
if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
$hidegeneratedfilelistifempty = 1;
if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
$hidegeneratedfilelistifempty = 0;
}
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
$formfile = new FormFile($db);

View File

@ -136,9 +136,15 @@ class CashControl extends CommonObject
$error = 0;
// Clean data
if (empty($this->cash)) $this->cash = 0;
if (empty($this->cheque)) $this->cheque = 0;
if (empty($this->card)) $this->card = 0;
if (empty($this->cash)) {
$this->cash = 0;
}
if (empty($this->cheque)) {
$this->cheque = 0;
}
if (empty($this->card)) {
$this->card = 0;
}
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."pos_cash_fence (";
@ -216,8 +222,7 @@ class CashControl extends CommonObject
$error = 0;
// Protection
if ($this->status == self::STATUS_VALIDATED)
{
if ($this->status == self::STATUS_VALIDATED) {
dol_syslog(get_class($this)."::valid action abandonned: already validated", LOG_WARNING);
return 0;
}
@ -256,11 +261,12 @@ class CashControl extends CommonObject
$this->fk_user_valid = $user->id;
}
if (!$error && !$notrigger)
{
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('CASHCONTROL_VALIDATE', $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
// End call triggers
}
@ -340,8 +346,7 @@ class CashControl extends CommonObject
public function LibStatut($status, $mode = 0)
{
// phpcs:enable
if (empty($this->labelStatus) || empty($this->labelStatusShort))
{
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;
//$langs->load("mymodule");
$this->labelStatus[0] = $langs->trans('Draft');
@ -351,7 +356,9 @@ class CashControl extends CommonObject
}
$statusType = 'status0';
if ($status == self::STATUS_VALIDATED) $statusType = 'status6';
if ($status == self::STATUS_VALIDATED) {
$statusType = 'status6';
}
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}
@ -370,7 +377,9 @@ class CashControl extends CommonObject
{
global $conf, $langs, $hookmanager;
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
if (!empty($conf->dol_no_mouse_hover)) {
$notooltip = 1; // Force disable tooltips
}
$result = '';
@ -382,19 +391,20 @@ class CashControl extends CommonObject
$url = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$this->id;
if ($option != 'nolink')
{
if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
$add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
}
$linkclose = '';
if (empty($notooltip))
{
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
if (empty($notooltip)) {
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowMyObject");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
@ -402,20 +412,26 @@ class CashControl extends CommonObject
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
/*
$hookmanager->initHooks(array('myobjectdao'));
$parameters=array('id'=>$this->id);
$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $linkclose = $hookmanager->resPrint;
*/
} else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
$hookmanager->initHooks(array('myobjectdao'));
$parameters=array('id'=>$this->id);
$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $linkclose = $hookmanager->resPrint;
*/
} else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
$linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
if ($withpicto) {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto != 2) {
$result .= $this->ref;
}
$result .= $linkend;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');

View File

@ -29,8 +29,12 @@
* \brief List of bank transactions
*/
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
if (!defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
}
if (!defined('NOBROWSERNOTIF')) {
define('NOBROWSERNOTIF', '1'); // Disable browser notification
}
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
@ -120,10 +124,15 @@ else
dol_print_error('Value for key = '.$key.' not supported');
exit;
}*/
if ($syear && !$smonth) $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
elseif ($syear && $smonth && !$sday) $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
elseif ($syear && $smonth && $sday) $sql .= " AND datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $smonth, $sday, $syear))."'";
else dol_print_error('', 'Year not defined');
if ($syear && !$smonth) {
$sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
} elseif ($syear && $smonth && !$sday) {
$sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
} elseif ($syear && $smonth && $sday) {
$sql .= " AND datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $smonth, $sday, $syear))."'";
} else {
dol_print_error('', 'Year not defined');
}
$resql = $db->query($sql);
if ($resql) {
@ -132,8 +141,11 @@ if ($resql) {
print "<!-- title of cash fence -->\n";
print "<center><h2>";
if ($cashcontrol->status != $cashcontrol::STATUS_DRAFT) print $langs->trans("CashControl")." ".$cashcontrol->id;
else print $langs->trans("CashControl")." - ".$langs->trans("Draft");
if ($cashcontrol->status != $cashcontrol::STATUS_DRAFT) {
print $langs->trans("CashControl")." ".$cashcontrol->id;
} else {
print $langs->trans("CashControl")." - ".$langs->trans("Draft");
}
print "<br>".$langs->trans("DateCreationShort").": ".dol_print_date($cashcontrol->date_creation, 'dayhour');
print "</h2></center>";
@ -194,13 +206,17 @@ if ($resql) {
print '<td class="nowrap left">';
print $invoicetmp->getNomUrl(1);
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
// Date ope
print '<td class="nowrap left">';
print '<span id="dateoperation_'.$objp->rowid.'">'.dol_print_date($db->jdate($objp->do), "day")."</span>";
print "</td>\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
// Bank account
print '<td class="nowrap right">';
@ -215,20 +231,30 @@ if ($resql) {
} elseif ($objp->code == 'CB') {
$bank += $objp->amount;
} else {
if ($conf->global->$var1 == $bankaccount->id) $cash += $objp->amount;
if ($conf->global->$var1 == $bankaccount->id) {
$cash += $objp->amount;
}
//elseif ($conf->global->$var2 == $bankaccount->id) $bank+=$objp->amount;
//elseif ($conf->global->$var3 == $bankaccount->id) $cheque+=$objp->amount;
else $other += $objp->amount;
else {
$other += $objp->amount;
}
}
print "</td>\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
// Type
print '<td class="right">';
print $objp->code;
if (empty($amountpertype[$objp->code])) $amountpertype[$objp->code] = 0;
print $objp->code;
if (empty($amountpertype[$objp->code])) {
$amountpertype[$objp->code] = 0;
}
print "</td>\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
// Debit
print '<td class="right">';
@ -238,8 +264,12 @@ if ($resql) {
$amountpertype[$objp->code] += $objp->amount;
}
print "</td>\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totaldebfield';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'totaldebfield';
}
// Credit
print '<td class="right">';
@ -249,8 +279,12 @@ if ($resql) {
$amountpertype[$objp->code] -= $objp->amount;
}
print "</td>\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalcredfield';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'totalcredfield';
}
print "</tr>";
@ -297,7 +331,7 @@ if ($resql) {
$sql = "UPDATE ".MAIN_DB_PREFIX."pos_cash_fence ";
$sql .= "SET";
$sql .= " cash='".$db->escape($cash)."'";
$sql .= ", card='".$db->escape($bank)."'";
$sql .= ", card='".$db->escape($bank)."'";
$sql .= " where rowid=".$id;
$db->query($sql);
*/

View File

@ -45,13 +45,17 @@ $hookmanager->initHooks(array('specialexpensesindex'));
$langs->loadLangs(array('compta', 'bills'));
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'tax|salaries', '', '', 'charges|');
$mode = GETPOST("mode", 'alpha');
$year = GETPOST("year", 'int');
$filtre = GETPOST("filtre", 'alpha');
if (!$year) { $year = date("Y", time()); }
if (!$year) {
$year = date("Y", time());
}
$search_account = GETPOST('search_account', 'int');
@ -59,12 +63,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortfield) $sortfield = "cs.date_ech";
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) {
$sortfield = "cs.date_ech";
}
if (!$sortorder) {
$sortorder = "DESC";
}
/*
@ -82,16 +92,26 @@ llxHeader('', $langs->trans("SpecialExpensesArea"));
$title = $langs->trans("SpecialExpensesArea");
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
if ($sortfield) $param .= '&sortfield='.$sortfield;
if ($sortorder) $param .= '&sortorder='.$sortorder;
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.$contextpage;
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.$limit;
}
if ($sortfield) {
$param .= '&sortfield='.$sortfield;
}
if ($sortorder) {
$param .= '&sortorder='.$sortorder;
}
$totalnboflines = 0;
$num = 0;
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
@ -102,13 +122,14 @@ print '<input type="hidden" name="mode" value="'.$mode.'">';
$nav = ($year ? '<a href="index.php?year='.($year - 1).$param.'">'.img_previous($langs->trans("Previous"), 'class="valignbottom"')."</a> ".$langs->trans("Year").' '.$year.' <a href="index.php?year='.($year + 1).$param.'">'.img_next($langs->trans("Next"), 'class="valignbottom"')."</a>" : "");
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'object_payment', 0, $nav, '', $limit, 1);
if ($year) $param .= '&year='.$year;
if ($year) {
$param .= '&year='.$year;
}
print '<span class="opacitymedium">'.$langs->trans("DescTaxAndDividendsArea").'</span><br>';
print "<br>";
if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
{
if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire) {
// Social contributions only
print load_fiche_titre($langs->trans("SocialContributionsPayments").($year ? ' ('.$langs->trans("Year").' '.$year.')' : ''), '', '');
@ -121,7 +142,9 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "pc.rowid", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pc.datep", "", $param, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
if (!empty($conf->banque->enabled)) print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
if (!empty($conf->banque->enabled)) {
print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
}
print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "pc.amount", "", $param, 'class="right"', $sortfield, $sortorder);
print "</tr>\n";
@ -138,8 +161,7 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql .= " WHERE cs.fk_type = c.id";
$sql .= " AND cs.entity IN (".getEntity("tax").")";
if ($year > 0)
{
if ($year > 0) {
$sql .= " AND (";
// Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
// ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
@ -147,27 +169,29 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
$sql .= " OR (cs.periode IS NULL AND cs.date_ech between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')";
$sql .= ")";
}
if (preg_match('/^cs\./', $sortfield) || preg_match('/^c\./', $sortfield) || preg_match('/^pc\./', $sortfield) || preg_match('/^pct\./', $sortfield)) $sql .= $db->order($sortfield, $sortorder);
if (preg_match('/^cs\./', $sortfield) || preg_match('/^c\./', $sortfield) || preg_match('/^pc\./', $sortfield) || preg_match('/^pct\./', $sortfield)) {
$sql .= $db->order($sortfield, $sortorder);
}
//$sql.= $db->plimit($limit+1,$offset);
//print $sql;
dol_syslog("compta/charges/index.php: select payment", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$total = 0;
$totalnb = 0;
$totalpaye = 0;
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';
// Date
$date = $obj->periode;
if (empty($date)) $date = $obj->date_ech;
if (empty($date)) {
$date = $obj->date_ech;
}
print '<td>'.dol_print_date($date, 'day').'</td>';
// Label
print '<td>';
@ -188,14 +212,14 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day').'</td>';
// Type payment
print '<td>';
if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
if ($obj->payment_code) {
print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
}
print $obj->num_payment.'</td>';
// Account
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
print '<td>';
if ($obj->fk_bank > 0)
{
if ($obj->fk_bank > 0) {
//$accountstatic->fetch($obj->fk_bank);
$accountstatic->id = $obj->bid;
$accountstatic->ref = $obj->bref;
@ -204,12 +228,16 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
$accountstatic->accountancy_journal = $obj->accountancy_journal;
$accountstatic->label = $obj->blabel;
print $accountstatic->getNomUrl(1);
} else print '&nbsp;';
} else {
print '&nbsp;';
}
print '</td>';
}
// Paid
print '<td class="right">';
if ($obj->totalpaye) print price($obj->totalpaye);
if ($obj->totalpaye) {
print price($obj->totalpaye);
}
print '</td>';
print '</tr>';
@ -223,7 +251,9 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
print '<td align="center" class="liste_total">&nbsp;</td>';
print '<td align="center" class="liste_total">&nbsp;</td>';
print '<td align="center" class="liste_total">&nbsp;</td>';
if (!empty($conf->banque->enabled)) print '<td></td>';
if (!empty($conf->banque->enabled)) {
print '<td></td>';
}
print '<td class="liste_total right">'.price($totalpaye)."</td>";
print "</tr>";
} else {
@ -233,8 +263,7 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
}
// VAT
if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
{
if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire) {
print "<br>";
$tva = new Tva($db);
@ -249,17 +278,17 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pv.fk_typepayment = pct.id";
$sql .= " WHERE pv.entity IN (".getEntity("tax").")";
if ($year > 0)
{
if ($year > 0) {
// Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
// ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
$sql .= " AND pv.datev between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'";
}
if (preg_match('/^pv\./', $sortfield)) $sql .= $db->order($sortfield, $sortorder);
if (preg_match('/^pv\./', $sortfield)) {
$sql .= $db->order($sortfield, $sortorder);
}
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
$total = 0;
@ -271,12 +300,13 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "pv.rowid", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pv.datev", "", $param, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
if (!empty($conf->banque->enabled)) print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
if (!empty($conf->banque->enabled)) {
print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
}
print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "pv.amount", "", $param, 'class="right"', $sortfield, $sortorder);
print "</tr>\n";
$var = 1;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($result);
$total = $total + $obj->amount;
@ -299,15 +329,15 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
// Type payment
print '<td>';
if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
if ($obj->payment_code) {
print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
}
print $obj->num_payment.'</td>';
// Account
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
print '<td>';
if ($obj->fk_bank > 0)
{
if ($obj->fk_bank > 0) {
//$accountstatic->fetch($obj->fk_bank);
$accountstatic->id = $obj->bid;
$accountstatic->ref = $obj->bref;
@ -316,7 +346,9 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
$accountstatic->accountancy_journal = $obj->accountancy_journal;
$accountstatic->label = $obj->blabel;
print $accountstatic->getNomUrl(1);
} else print '&nbsp;';
} else {
print '&nbsp;';
}
print '</td>';
}
@ -343,16 +375,13 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
}
// Localtax
if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
{
if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
$j = 1;
$numlt = 3;
} elseif ($mysoc->localtax1_assuj == "1")
{
} elseif ($mysoc->localtax1_assuj == "1") {
$j = 1;
$numlt = 2;
} elseif ($mysoc->localtax2_assuj == "1")
{
} elseif ($mysoc->localtax2_assuj == "1") {
$j = 2;
$numlt = 3;
} else {
@ -360,8 +389,7 @@ if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1")
$numlt = 0;
}
while ($j < $numlt)
{
while ($j < $numlt) {
print "<br>";
$tva = new Tva($db);
@ -372,17 +400,17 @@ while ($j < $numlt)
$sql = "SELECT pv.rowid, pv.amount, pv.label, pv.datev as dm, pv.datep as dp";
$sql .= " FROM ".MAIN_DB_PREFIX."localtax as pv";
$sql .= " WHERE pv.entity = ".$conf->entity." AND localtaxtype = ".$j;
if ($year > 0)
{
if ($year > 0) {
// Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
// ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
$sql .= " AND pv.datev between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'";
}
if (preg_match('/^pv/', $sortfield)) $sql .= $db->order($sortfield, $sortorder);
if (preg_match('/^pv/', $sortfield)) {
$sql .= $db->order($sortfield, $sortorder);
}
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
$total = 0;
@ -396,8 +424,7 @@ while ($j < $numlt)
print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "pv.amount", "", $param, 'class="right"', $sortfield, $sortorder);
print "</tr>\n";
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($result);
$total = $total + $obj->amount;
@ -441,107 +468,107 @@ while ($j < $numlt)
/*
if (!empty($conf->salaries->enabled) && !empty($user->rights->salaries->read))
{
$sal = new PaymentSalary($db);
$sal = new PaymentSalary($db);
print "<br>";
print "<br>";
print load_fiche_titre($langs->trans("SalariesPayments").($year ? ' ('.$langs->trans("Year").' '.$year.')' : ''), '', '');
print load_fiche_titre($langs->trans("SalariesPayments").($year ? ' ('.$langs->trans("Year").' '.$year.')' : ''), '', '');
$sql = "SELECT s.rowid, s.amount, s.label, s.datep as datep, s.datev as datev, s.datesp, s.dateep, s.salary, s.fk_bank, u.salary as current_salary,";
$sql = "SELECT s.rowid, s.amount, s.label, s.datep as datep, s.datev as datev, s.datesp, s.dateep, s.salary, s.fk_bank, u.salary as current_salary,";
$sql .= " pct.code as payment_code,";
$sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel";
$sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
$sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON s.fk_typepayment = pct.id";
$sql .= " , ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE s.entity IN (".getEntity('user').")";
$sql .= " AND u.rowid = s.fk_user";
if ($year > 0)
{
$sql .= " AND (s.datesp between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'";
$sql .= " OR s.dateep between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."')";
}
if (preg_match('/^s\./', $sortfield)) $sql .= $db->order($sortfield, $sortorder);
$sql .= " WHERE s.entity IN (".getEntity('user').")";
$sql .= " AND u.rowid = s.fk_user";
if ($year > 0)
{
$sql .= " AND (s.datesp between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'";
$sql .= " OR s.dateep between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."')";
}
if (preg_match('/^s\./', $sortfield)) $sql .= $db->order($sortfield, $sortorder);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
$total = 0;
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "s.dateep", "", $param, 'width="140px"', $sortfield, $sortorder);
print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "s.label", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "s.rowid", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "s.datep", "", $param, 'align="center"', $sortfield, $sortorder);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
$total = 0;
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "s.dateep", "", $param, 'width="140px"', $sortfield, $sortorder);
print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "s.label", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "s.rowid", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "s.datep", "", $param, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
if (!empty($conf->banque->enabled)) print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder);
print "</tr>\n";
print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder);
print "</tr>\n";
while ($i < $num)
{
$obj = $db->fetch_object($result);
while ($i < $num)
{
$obj = $db->fetch_object($result);
$total = $total + $obj->amount;
$total = $total + $obj->amount;
print '<tr class="oddeven">';
print '<tr class="oddeven">';
print '<td class="left">'.dol_print_date($db->jdate($obj->dateep), 'day').'</td>'."\n";
print '<td class="left">'.dol_print_date($db->jdate($obj->dateep), 'day').'</td>'."\n";
print "<td>".$obj->label."</td>\n";
print "<td>".$obj->label."</td>\n";
// Ref payment
$sal_static->id = $obj->rowid;
$sal_static->ref = $obj->rowid;
print '<td class="left">'.$sal_static->getNomUrl(1)."</td>\n";
// Ref payment
$sal_static->id = $obj->rowid;
$sal_static->ref = $obj->rowid;
print '<td class="left">'.$sal_static->getNomUrl(1)."</td>\n";
// Date
print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day')."</td>\n";
// Date
print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day')."</td>\n";
// Type payment
print '<td>';
if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
print $obj->num_payment.'</td>';
// Type payment
print '<td>';
if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
print $obj->num_payment.'</td>';
// Account
if (!empty($conf->banque->enabled))
{
print '<td>';
if ($obj->fk_bank > 0)
{
//$accountstatic->fetch($obj->fk_bank);
$accountstatic->id = $obj->bid;
$accountstatic->ref = $obj->bref;
$accountstatic->number = $obj->bnumber;
$accountstatic->accountancy_number = $obj->account_number;
$accountstatic->accountancy_journal = $obj->accountancy_journal;
$accountstatic->label = $obj->blabel;
print $accountstatic->getNomUrl(1);
} else print '&nbsp;';
print '</td>';
}
// Account
if (!empty($conf->banque->enabled))
{
print '<td>';
if ($obj->fk_bank > 0)
{
//$accountstatic->fetch($obj->fk_bank);
$accountstatic->id = $obj->bid;
$accountstatic->ref = $obj->bref;
$accountstatic->number = $obj->bnumber;
$accountstatic->accountancy_number = $obj->account_number;
$accountstatic->accountancy_journal = $obj->accountancy_journal;
$accountstatic->label = $obj->blabel;
print $accountstatic->getNomUrl(1);
} else print '&nbsp;';
print '</td>';
}
// Paid
print '<td class="right">'.price($obj->amount)."</td>";
print "</tr>\n";
// Paid
print '<td class="right">'.price($obj->amount)."</td>";
print "</tr>\n";
$i++;
}
print '<tr class="liste_total"><td colspan="6">'.$langs->trans("Total").'</td>';
print '<td class="right">'.price($total)."</td>";
print "</tr>";
$i++;
}
print '<tr class="liste_total"><td colspan="6">'.$langs->trans("Total").'</td>';
print '<td class="right">'.price($total)."</td>";
print "</tr>";
print "</table>";
$db->free($result);
print "</table>";
$db->free($result);
print "<br>";
} else {
dol_print_error($db);
}
print "<br>";
} else {
dol_print_error($db);
}
}
*/

View File

@ -30,14 +30,14 @@ require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
$action = GETPOST('action', 'aZ09');
// Secrutiy check
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
if (!$user->rights->facture->lire)
accessforbidden();
if (!$user->rights->facture->lire) {
accessforbidden();
}
// Load translation files required by the page
$langs->load("companies");
@ -48,12 +48,18 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) $sortfield = "nom";
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "nom";
}
/*
@ -64,14 +70,12 @@ llxHeader();
$thirdpartystatic = new Societe($db);
if ($action == 'note')
{
if ($action == 'note') {
$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='".$db->escape($note)."' WHERE rowid=".$socid;
$result = $db->query($sql);
}
if ($mode == 'search')
{
if ($mode == 'search') {
$resql = $db->query($sql);
if ($resql) {
if ($db->num_rows($resql) == 1) {
@ -90,40 +94,39 @@ if ($mode == 'search')
$sql = "SELECT s.rowid, s.nom as name, s.client, s.town, s.datec, s.datea";
$sql .= ", st.libelle as stcomm, s.prefix_comm, s.code_client, s.code_compta ";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", sc.fk_soc, sc.fk_user ";
}
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.fk_stcomm = st.id AND s.client in (1, 3)";
$sql .= " AND s.entity IN (".getEntity('societe').")";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if (dol_strlen($stcomm))
{
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if (dol_strlen($stcomm)) {
$sql .= " AND s.fk_stcomm=".$stcomm;
}
if ($socname)
{
if ($socname) {
$sql .= natural_search("s.nom", $socname);
$sortfield = "s.nom";
$sortorder = "ASC";
}
if ($_GET["search_nom"])
{
if ($_GET["search_nom"]) {
$sql .= natural_search("s.nom", GETPOST("search_nom"));
}
if ($_GET["search_compta"])
{
if ($_GET["search_compta"]) {
$sql .= natural_search("s.code_compta", GETPOST("search_compta"));
}
if ($_GET["search_code_client"])
{
if ($_GET["search_code_client"]) {
$sql .= natural_search("s.code_client", GETPOST("search_code_client"));
}
if (dol_strlen($begin))
{
if (dol_strlen($begin)) {
$sql .= natural_search("s.nom", $begin);
}
if ($socid)
{
if ($socid) {
$sql .= " AND s.rowid = ".$socid;
}
$sql .= " ORDER BY $sortfield $sortorder ";
@ -131,8 +134,7 @@ $sql .= $db->plimit($conf->liste_limit + 1, $offset);
//print $sql;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -173,8 +175,7 @@ if ($resql)
print '</td>';
print "</tr>\n";
while ($i < min($num, $conf->liste_limit))
{
while ($i < min($num, $conf->liste_limit)) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven">';

View File

@ -29,8 +29,7 @@ require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/trip.lib.php';
require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
}
@ -40,7 +39,9 @@ $langs->load("trips");
// Security check
$id = GETPOST('id', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'deplacement', $id, '');
$action = GETPOST('action', 'aZ09');
@ -60,48 +61,38 @@ $permissionnote = $user->rights->deplacement->creer; // Used by the include of a
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
if ($action == 'validate' && $user->rights->deplacement->creer)
{
if ($action == 'validate' && $user->rights->deplacement->creer) {
$object->fetch($id);
if ($object->statut == Deplacement::STATUS_DRAFT)
{
if ($object->statut == Deplacement::STATUS_DRAFT) {
$result = $object->setStatut(1);
if ($result > 0)
{
if ($result > 0) {
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit;
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
} elseif ($action == 'classifyrefunded' && $user->rights->deplacement->creer)
{
} elseif ($action == 'classifyrefunded' && $user->rights->deplacement->creer) {
$object->fetch($id);
if ($object->statut == Deplacement::STATUS_VALIDATED)
{
if ($object->statut == Deplacement::STATUS_VALIDATED) {
$result = $object->setStatut(Deplacement::STATUS_REFUNDED);
if ($result > 0)
{
if ($result > 0) {
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit;
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
} elseif ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->deplacement->supprimer)
{
} elseif ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->deplacement->supprimer) {
$result = $object->delete($id);
if ($result >= 0)
{
if ($result >= 0) {
header("Location: index.php");
exit;
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
} elseif ($action == 'add' && $user->rights->deplacement->creer)
{
if (!GETPOST('cancel', 'alpha'))
{
} elseif ($action == 'add' && $user->rights->deplacement->creer) {
if (!GETPOST('cancel', 'alpha')) {
$error = 0;
$object->date = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
@ -113,28 +104,23 @@ if ($action == 'validate' && $user->rights->deplacement->creer)
$object->note_public = GETPOST('note_public', 'alpha');
$object->statut = Deplacement::STATUS_DRAFT;
if (!$object->date)
{
if (!$object->date) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
$error++;
}
if ($object->type == '-1')
{
if ($object->type == '-1') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
$error++;
}
if (!($object->fk_user > 0))
{
if (!($object->fk_user > 0)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Person")), null, 'errors');
$error++;
}
if (!$error)
{
if (!$error) {
$id = $object->create($user);
if ($id > 0)
{
if ($id > 0) {
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit;
} else {
@ -149,10 +135,8 @@ if ($action == 'validate' && $user->rights->deplacement->creer)
exit;
}
} // Update record
elseif ($action == 'update' && $user->rights->deplacement->creer)
{
if (!GETPOST('cancel', 'alpha'))
{
elseif ($action == 'update' && $user->rights->deplacement->creer) {
if (!GETPOST('cancel', 'alpha')) {
$result = $object->fetch($id);
$object->date = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
@ -165,8 +149,7 @@ elseif ($action == 'update' && $user->rights->deplacement->creer)
$result = $object->update($user);
if ($result > 0)
{
if ($result > 0) {
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit;
} else {
@ -177,23 +160,26 @@ elseif ($action == 'update' && $user->rights->deplacement->creer)
exit;
}
} // Set into a project
elseif ($action == 'classin' && $user->rights->deplacement->creer)
{
elseif ($action == 'classin' && $user->rights->deplacement->creer) {
$object->fetch($id);
$result = $object->setProject(GETPOST('projectid', 'int'));
if ($result < 0) dol_print_error($db, $object->error);
if ($result < 0) {
dol_print_error($db, $object->error);
}
} // Set fields
elseif ($action == 'setdated' && $user->rights->deplacement->creer)
{
elseif ($action == 'setdated' && $user->rights->deplacement->creer) {
$dated = dol_mktime(GETPOST('datedhour', 'int'), GETPOST('datedmin', 'int'), GETPOST('datedsec', 'int'), GETPOST('datedmonth', 'int'), GETPOST('datedday', 'int'), GETPOST('datedyear', 'int'));
$object->fetch($id);
$result = $object->setValueFrom('dated', $dated, '', '', 'date', '', $user, 'DEPLACEMENT_MODIFY');
if ($result < 0) dol_print_error($db, $object->error);
} elseif ($action == 'setkm' && $user->rights->deplacement->creer)
{
if ($result < 0) {
dol_print_error($db, $object->error);
}
} elseif ($action == 'setkm' && $user->rights->deplacement->creer) {
$object->fetch($id);
$result = $object->setValueFrom('km', GETPOST('km', 'int'), '', null, 'text', '', $user, 'DEPLACEMENT_MODIFY');
if ($result < 0) dol_print_error($db, $object->error);
if ($result < 0) {
dol_print_error($db, $object->error);
}
}
@ -208,8 +194,7 @@ $form = new Form($db);
/*
* Action create
*/
if ($action == 'create')
{
if ($action == 'create') {
//WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
@ -258,8 +243,7 @@ if ($action == 'create')
print '</td></tr>';
// Private note
if (empty($user->socid))
{
if (empty($user->socid)) {
print '<tr>';
print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
print '<td>';
@ -284,23 +268,19 @@ if ($action == 'create')
print '</div>';
print '</form>';
} elseif ($id)
{
} elseif ($id) {
$result = $object->fetch($id);
if ($result > 0)
{
if ($result > 0) {
$head = trip_prepare_head($object);
print dol_get_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip');
if ($action == 'edit' && $user->rights->deplacement->creer)
{
if ($action == 'edit' && $user->rights->deplacement->creer) {
//WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$soc = new Societe($db);
if ($object->socid)
{
if ($object->socid) {
$soc->fetch($object->socid);
}
@ -355,8 +335,7 @@ if ($action == 'create')
print "</td></tr>";
// Private note
if (empty($user->socid))
{
if (empty($user->socid)) {
print '<tr><td class="tdtop">'.$langs->trans("NotePrivate").'</td>';
print '<td>';
@ -384,15 +363,16 @@ if ($action == 'create')
print '</div>';
} else {
/*
* Confirm delete trip
*/
if ($action == 'delete')
{
* Confirm delete trip
*/
if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteTrip"), $langs->trans("ConfirmDeleteTrip"), "confirm_delete");
}
$soc = new Societe($db);
if ($object->socid) $soc->fetch($object->socid);
if ($object->socid) {
$soc->fetch($object->socid);
}
print '<table class="border centpercent">';
@ -436,12 +416,13 @@ if ($action == 'create')
// Where
print '<tr><td>'.$langs->trans("CompanyVisited").'</td>';
print '<td>';
if ($soc->id) print $soc->getNomUrl(1);
if ($soc->id) {
print $soc->getNomUrl(1);
}
print '</td></tr>';
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load('projects');
print '<tr>';
print '<td>';
@ -449,16 +430,14 @@ if ($action == 'create')
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project');
print '</td>';
if ($action != 'classify' && $user->rights->deplacement->creer)
{
if ($action != 'classify' && $user->rights->deplacement->creer) {
print '<td class="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">';
print img_edit($langs->trans('SetProject'), 1);
print '</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
if ($action == 'classify')
{
if ($action == 'classify') {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1);
} else {
$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0);
@ -484,43 +463,36 @@ if ($action == 'create')
print '</div>';
/*
* Barre d'actions
*/
* Barre d'actions
*/
print '<div class="tabsAction">';
if ($object->statut < Deplacement::STATUS_REFUNDED) // if not refunded
{
if ($user->rights->deplacement->creer)
{
if ($object->statut < Deplacement::STATUS_REFUNDED) { // if not refunded
if ($user->rights->deplacement->creer) {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$id.'">'.$langs->trans('Modify').'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Modify').'</a>';
}
}
if ($object->statut == Deplacement::STATUS_DRAFT) // if draft
{
if ($user->rights->deplacement->creer)
{
if ($object->statut == Deplacement::STATUS_DRAFT) { // if draft
if ($user->rights->deplacement->creer) {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&id='.$id.'">'.$langs->trans('Validate').'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Validate').'</a>';
}
}
if ($object->statut == Deplacement::STATUS_VALIDATED) // if validated
{
if ($user->rights->deplacement->creer)
{
if ($object->statut == Deplacement::STATUS_VALIDATED) { // if validated
if ($user->rights->deplacement->creer) {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=classifyrefunded&id='.$id.'">'.$langs->trans('ClassifyRefunded').'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('ClassifyRefunded').'</a>';
}
}
if ($user->rights->deplacement->supprimer)
{
if ($user->rights->deplacement->supprimer) {
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$id.'">'.$langs->trans('Delete').'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans('Delete').'</a>';

View File

@ -141,13 +141,11 @@ class Deplacement extends CommonObject
global $conf;
// Check parameters
if (empty($this->type) || $this->type < 0)
{
if (empty($this->type) || $this->type < 0) {
$this->error = 'ErrorBadParameter';
return -1;
}
if (empty($this->fk_user) || $this->fk_user < 0)
{
if (empty($this->fk_user) || $this->fk_user < 0) {
$this->error = 'ErrorBadParameter';
return -1;
}
@ -181,22 +179,19 @@ class Deplacement extends CommonObject
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."deplacement");
// Call trigger
$result = $this->call_trigger('DEPLACEMENT_CREATE', $user);
if ($result < 0)
{
if ($result < 0) {
$this->db->rollback();
return -2;
}
// End call triggers
$result = $this->update($user);
if ($result > 0)
{
if ($result > 0) {
$this->db->commit();
return $this->id;
} else {
@ -225,19 +220,18 @@ class Deplacement extends CommonObject
$this->km = price2num($this->km);
// Check parameters
if (!is_numeric($this->km)) $this->km = 0;
if (empty($this->date))
{
if (!is_numeric($this->km)) {
$this->km = 0;
}
if (empty($this->date)) {
$this->error = 'ErrorBadParameter';
return -1;
}
if (empty($this->type) || $this->type < 0)
{
if (empty($this->type) || $this->type < 0) {
$this->error = 'ErrorBadParameter';
return -1;
}
if (empty($this->fk_user) || $this->fk_user < 0)
{
if (empty($this->fk_user) || $this->fk_user < 0) {
$this->error = 'ErrorBadParameter';
return -1;
}
@ -259,8 +253,7 @@ class Deplacement extends CommonObject
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$this->db->commit();
return 1;
} else {
@ -282,13 +275,15 @@ class Deplacement extends CommonObject
$sql = "SELECT rowid, fk_user, type, fk_statut, km, fk_soc, dated, note_private, note_public, fk_projet as fk_project, extraparams";
$sql .= " FROM ".MAIN_DB_PREFIX."deplacement";
$sql .= " WHERE entity IN (".getEntity('deplacement').")";
if ($ref) $sql .= " AND ref ='".$this->db->escape($ref)."'";
else $sql .= " AND rowid = ".$id;
if ($ref) {
$sql .= " AND ref ='".$this->db->escape($ref)."'";
} else {
$sql .= " AND rowid = ".$id;
}
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
@ -326,8 +321,7 @@ class Deplacement extends CommonObject
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$this->db->commit();
return 1;
} else {
@ -362,32 +356,42 @@ class Deplacement extends CommonObject
// phpcs:enable
global $langs;
if ($mode == 0)
{
if ($mode == 0) {
return $langs->trans($this->statuts[$status]);
} elseif ($mode == 1)
{
} elseif ($mode == 1) {
return $langs->trans($this->statuts_short[$status]);
} elseif ($mode == 2)
{
if ($status == 0) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts_short[$status]);
elseif ($status == 1) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts_short[$status]);
elseif ($status == 2) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]);
} elseif ($mode == 3)
{
if ($status == 0 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
elseif ($status == 1 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
elseif ($status == 2 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
} elseif ($mode == 4)
{
if ($status == 0 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]);
elseif ($status == 1 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]);
elseif ($status == 2 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]);
} elseif ($mode == 5)
{
if ($status == 0 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
elseif ($status == 1 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
elseif ($status == 2 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
} elseif ($mode == 2) {
if ($status == 0) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts_short[$status]);
} elseif ($status == 1) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts_short[$status]);
} elseif ($status == 2) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]);
}
} elseif ($mode == 3) {
if ($status == 0 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
} elseif ($status == 1 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
} elseif ($status == 2 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
}
} elseif ($mode == 4) {
if ($status == 0 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]);
} elseif ($status == 1 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]);
} elseif ($status == 2 && !empty($this->statuts_short[$status])) {
return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]);
}
} elseif ($mode == 5) {
if ($status == 0 && !empty($this->statuts_short[$status])) {
return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut0');
} elseif ($status == 1 && !empty($this->statuts_short[$status])) {
return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut4');
} elseif ($status == 2 && !empty($this->statuts_short[$status])) {
return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut6');
}
}
}
@ -410,9 +414,15 @@ class Deplacement extends CommonObject
$picto = 'trip';
if ($withpicto) $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
if ($withpicto && $withpicto != 2) $result .= ' ';
if ($withpicto != 2) $result .= $link.$this->ref.$linkend;
if ($withpicto) {
$result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
}
if ($withpicto && $withpicto != 2) {
$result .= ' ';
}
if ($withpicto != 2) {
$result .= $link.$this->ref.$linkend;
}
return $result;
}
@ -435,12 +445,10 @@ class Deplacement extends CommonObject
dol_syslog(get_class($this)."::listOfTypes", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $this->db->fetch_object($result);
$ret[$obj->code] = (($langs->trans($obj->code) != $obj->code) ? $langs->trans($obj->code) : $obj->label);
$i++;
@ -468,20 +476,16 @@ class Deplacement extends CommonObject
dol_syslog(get_class($this).'::info', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
if ($obj->fk_user_author)
{
if ($obj->fk_user_author) {
$cuser = new User($this->db);
$cuser->fetch($obj->fk_user_author);
$this->user_creation = $cuser;
}
if ($obj->fk_user_modif)
{
if ($obj->fk_user_modif) {
$muser = new User($this->db);
$muser->fetch($obj->fk_user_modif);
$this->user_modification = $muser;

View File

@ -64,12 +64,14 @@ class DeplacementStats extends Stats
$this->where = " fk_statut > 0";
$this->where .= " AND entity = ".$conf->entity;
if ($this->socid)
{
if ($this->socid) {
$this->where .= " AND fk_soc = ".$this->socid;
}
if (is_array($this->userid) && count($this->userid) > 0) $this->where .= ' AND fk_user IN ('.join(',', $this->userid).')';
elseif ($this->userid > 0) $this->where .= ' AND fk_user = '.$this->userid;
if (is_array($this->userid) && count($this->userid) > 0) {
$this->where .= ' AND fk_user IN ('.join(',', $this->userid).')';
} elseif ($this->userid > 0) {
$this->where .= ' AND fk_user = '.$this->userid;
}
}

View File

@ -43,7 +43,9 @@ $action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'deplacement', $id, '');
@ -52,12 +54,18 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) $sortfield = "name";
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "name";
}
$object = new Deplacement($db);
@ -83,8 +91,7 @@ $form = new Form($db);
llxHeader("", "", $langs->trans("TripCard"));
if ($object->id)
{
if ($object->id) {
$object->fetch_thirdparty();
$head = trip_prepare_head($object);
@ -95,8 +102,7 @@ if ($object->id)
// Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0;
foreach ($filearray as $key => $file)
{
foreach ($filearray as $key => $file) {
$totalsize += $file['size'];
}

View File

@ -32,19 +32,27 @@ $langs->loadLangs(array('companies', 'users', 'trips'));
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'deplacement', '', '');
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "d.dated";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "d.dated";
}
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
@ -67,17 +75,17 @@ $totalnb = 0;
$sql = "SELECT count(d.rowid) as nb, sum(d.km) as km, d.type";
$sql .= " FROM ".MAIN_DB_PREFIX."deplacement as d";
$sql .= " WHERE d.entity = ".$conf->entity;
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql .= ' AND d.fk_user IN ('.join(',', $childids).')';
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
$sql .= ' AND d.fk_user IN ('.join(',', $childids).')';
}
$sql .= " GROUP BY d.type";
$sql .= " ORDER BY d.type";
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $db->fetch_object($result);
$somme[$objp->type] = $objp->km;
@ -104,13 +112,11 @@ print '<td colspan="4">'.$langs->trans("Statistics").'</td>';
print "</tr>\n";
$listoftype = $tripandexpense_static->listOfTypes();
foreach ($listoftype as $code => $label)
{
foreach ($listoftype as $code => $label) {
$dataseries[] = array($label, (isset($nb[$code]) ? (int) $nb[$code] : 0));
}
if ($conf->use_javascript_ajax)
{
if ($conf->use_javascript_ajax) {
print '<tr><td align="center" colspan="4">';
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
@ -144,18 +150,25 @@ $langs->load("boxes");
$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, d.rowid, d.dated as date, d.tms as dm, d.km, d.fk_statut";
$sql .= " FROM ".MAIN_DB_PREFIX."deplacement as d, ".MAIN_DB_PREFIX."user as u";
if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$user->socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE u.rowid = d.fk_user";
$sql .= " AND d.entity = ".$conf->entity;
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql .= ' AND d.fk_user IN ('.join(',', $childids).')';
if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND d.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND d.fk_soc = ".$socid;
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
$sql .= ' AND d.fk_user IN ('.join(',', $childids).')';
}
if (!$user->rights->societe->client->voir && !$user->socid) {
$sql .= " AND d.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND d.fk_soc = ".$socid;
}
$sql .= $db->order("d.tms", "DESC");
$sql .= $db->plimit($max, 0);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$var = false;
$num = $db->num_rows($result);
@ -168,14 +181,12 @@ if ($result)
print '<td class="right">'.$langs->trans("DateModificationShort").'</td>';
print '<td width="16">&nbsp;</td>';
print '</tr>';
if ($num)
{
if ($num) {
$total_ttc = $totalam = $total = 0;
$deplacementstatic = new Deplacement($db);
$userstatic = new User($db);
while ($i < $num && $i < $max)
{
while ($i < $num && $i < $max) {
$obj = $db->fetch_object($result);
$deplacementstatic->ref = $obj->rowid;
$deplacementstatic->id = $obj->rowid;
@ -196,7 +207,9 @@ if ($result)
print '<tr class="oddeven"><td colspan="2" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
}
print '</table><br>';
} else dol_print_error($db);
} else {
dol_print_error($db);
}
print '</div></div></div>';

View File

@ -32,7 +32,9 @@ $langs->load("trips");
// Security check
$id = GETPOST('id', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'deplacement', $id, '');
@ -42,8 +44,7 @@ $result = restrictedArea($user, 'deplacement', $id, '');
llxHeader();
if ($id)
{
if ($id) {
$object = new Deplacement($db);
$object->fetch($id);
$object->info($id);

View File

@ -36,7 +36,9 @@ $langs->loadLangs(array('companies', 'users', 'trips'));
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'deplacement', '', '');
$search_ref = GETPOST('search_ref', 'int');
@ -47,19 +49,24 @@ $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "d.dated";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "d.dated";
}
$year = GETPOST("year");
$month = GETPOST("month");
$day = GETPOST("day");
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
$search_ref = "";
$search_name = "";
$search_company = "";
@ -89,20 +96,28 @@ $sql .= " u.lastname, u.firstname"; // Qui
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
$sql .= ", ".MAIN_DB_PREFIX."deplacement as d";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
}
$sql .= " WHERE d.fk_user = u.rowid";
$sql .= " AND d.entity = ".$conf->entity;
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql .= ' AND d.fk_user IN ('.join(',', $childids).')';
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id." OR d.fk_soc IS NULL) ";
if ($socid) $sql .= " AND s.rowid = ".$socid;
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
$sql .= ' AND d.fk_user IN ('.join(',', $childids).')';
}
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND (sc.fk_user = ".$user->id." OR d.fk_soc IS NULL) ";
}
if ($socid) {
$sql .= " AND s.rowid = ".$socid;
}
if ($search_ref) $sql .= " AND d.rowid=".$search_ref;
if ($search_name)
{
if ($search_ref) {
$sql .= " AND d.rowid=".$search_ref;
}
if ($search_name) {
$sql .= natural_search('u.lastname', $search_name);
}
if ($search_company)
{
if ($search_company) {
$sql .= natural_search('s.nom', $search_company);
}
$sql .= dolSqlDateFilter("d.dated", $day, $month, $year);
@ -112,8 +127,7 @@ $sql .= $db->plimit($limit + 1, $offset);
//print $sql;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
print_barre_liste($langs->trans("ListOfFees"), $page, $_SERVER["PHP_SELF"], "&socid=$socid", $sortfield, $sortorder, '', $num);
@ -140,7 +154,9 @@ if ($resql)
print '&nbsp;';
print '</td>';
print '<td class="liste_titre" align="center">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
}
print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
$formother->select_year($year ? $year : -1, 'year', 1, 20, 5);
print '</td>';
@ -159,12 +175,13 @@ if ($resql)
print '</td>';
print "</tr>\n";
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($resql);
$soc = new Societe($db);
if ($obj->socid) $soc->fetch($obj->socid);
if ($obj->socid) {
$soc->fetch($obj->socid);
}
print '<tr class="oddeven">';
// Id
@ -181,8 +198,11 @@ if ($resql)
print $userstatic->getNomUrl(1);
print '</td>';
if ($obj->socid) print '<td>'.$soc->getNomUrl(1).'</td>';
else print '<td>&nbsp;</td>';
if ($obj->socid) {
print '<td>'.$soc->getNomUrl(1).'</td>';
} else {
print '<td>&nbsp;</td>';
}
print '<td class="right">'.$obj->km.'</td>';

View File

@ -33,26 +33,29 @@ $langs->loadLangs(array('trips', 'companies'));
$WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
$userid = GETPOST('userid', 'int'); if ($userid < 0) $userid = 0;
$socid = GETPOST('socid', 'int'); if ($socid < 0) $socid = 0;
$userid = GETPOST('userid', 'int'); if ($userid < 0) {
$userid = 0;
}
$socid = GETPOST('socid', 'int'); if ($socid < 0) {
$socid = 0;
}
$id = GETPOST('id', 'int');
// Security check
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'deplacement', $id, '');
// Other security check
$childids = $user->getAllChildIds();
$childids[] = $user->id;
if ($userid > 0)
{
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous) && !in_array($userid, $childids))
{
if ($userid > 0) {
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous) && !in_array($userid, $childids)) {
accessforbidden();
exit;
}
@ -84,10 +87,11 @@ print load_fiche_titre($title, $mesg);
dol_mkdir($dir);
$useridtofilter = $userid; // Filter from parameters
if (empty($useridtofilter))
{
if (empty($useridtofilter)) {
$useridtofilter = $childids;
if (!empty($user->rights->deplacement->readall) || !empty($user->rights->deplacement->lire_tous)) $useridtofilter = 0;
if (!empty($user->rights->deplacement->readall) || !empty($user->rights->deplacement->lire_tous)) {
$useridtofilter = 0;
}
}
$stats = new DeplacementStats($db, $socid, $useridtofilter);
@ -104,12 +108,10 @@ $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file
$px1 = new DolGraph();
$mesg = $px1->isGraphKo();
if (!$mesg)
{
if (!$mesg) {
$px1->SetData($data);
$i = $startyear; $legend = array();
while ($i <= $endyear)
{
while ($i <= $endyear) {
$legend[] = $i;
$i++;
}
@ -136,12 +138,10 @@ $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;
$px2 = new DolGraph();
$mesg = $px2->isGraphKo();
if (!$mesg)
{
if (!$mesg) {
$px2->SetData($data);
$i = $startyear; $legend = array();
while ($i <= $endyear)
{
while ($i <= $endyear) {
$legend[] = $i;
$i++;
}
@ -162,25 +162,30 @@ if (!$mesg)
$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
if (!$user->rights->societe->client->voir || $user->socid)
{
if (!$user->rights->societe->client->voir || $user->socid) {
$filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
if ($mode == 'customer') {
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
}
if ($mode == 'supplier') {
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
}
} else {
$filename_avg = $dir.'/ordersaverage-'.$year.'.png';
if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
if ($mode == 'customer') {
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
}
if ($mode == 'supplier') {
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
}
}
$px3 = new DolGraph();
$mesg = $px3->isGraphKo();
if (!$mesg)
{
if (!$mesg) {
$px3->SetData($data);
$i = $startyear; $legend = array();
while ($i <= $endyear)
{
while ($i <= $endyear) {
$legend[] = $i;
$i++;
}
@ -205,7 +210,9 @@ $arrayyears = array();
foreach ($data as $val) {
$arrayyears[$val['year']] = $val['year'];
}
if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
if (!count($arrayyears)) {
$arrayyears[$nowyear] = $nowyear;
}
$h = 0;
@ -238,12 +245,16 @@ print '</td></tr>';
// User
print '<tr><td>'.$langs->trans("User").'</td><td>';
$include = '';
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $include = 'hierarchy';
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
$include = 'hierarchy';
}
print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'maxwidth300');
print '</td></tr>';
// Year
print '<tr><td>'.$langs->trans("Year").'</td><td>';
if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
if (!in_array($year, $arrayyears)) {
$arrayyears[$year] = $year;
}
arsort($arrayyears);
print $form->selectarray('year', $arrayyears, $year, 0);
print '</td></tr>';
@ -262,11 +273,9 @@ print '<td class="center">'.$langs->trans("AmountAverage").'</td>';
print '</tr>';
$oldyear = 0;
foreach ($data as $val)
{
foreach ($data as $val) {
$year = $val['year'];
while ($year && $oldyear > $year + 1)
{ // If we have empty year
while ($year && $oldyear > $year + 1) { // If we have empty year
$oldyear--;
print '<tr height="24">';
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
@ -292,7 +301,9 @@ print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
// Show graphs
print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
if ($mesg) { print $mesg; } else {
if ($mesg) {
print $mesg;
} else {
print $px1->show();
print "<br>\n";
print $px2->show();

View File

@ -38,13 +38,17 @@ $form = new Form($db);
// List of supported format
$tmptype2label = ExtraFields::$type2label;
$type2label = array('');
foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val);
foreach ($tmptype2label as $key => $val) {
$type2label[$key] = $langs->transnoentitiesnoconv($val);
}
$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'facture'; //Must be the $table_element of the class that manage extrafield
if (!$user->admin) accessforbidden();
if (!$user->admin) {
accessforbidden();
}
/*
@ -77,8 +81,7 @@ print dol_get_fiche_end();
// Buttons
if ($action != 'create' && $action != 'edit')
{
if ($action != 'create' && $action != 'edit') {
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create#newattrib\">".$langs->trans("NewAttribute")."</a>";
print "</div>";
@ -91,8 +94,7 @@ if ($action != 'create' && $action != 'edit')
*
*/
if ($action == 'create')
{
if ($action == 'create') {
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
@ -104,8 +106,7 @@ if ($action == 'create')
* Edition of an optional field
*
*/
if ($action == 'edit' && !empty($attrname))
{
if ($action == 'edit' && !empty($attrname)) {
$langs->load("members");
print "<br>";

View File

@ -39,13 +39,17 @@ $form = new Form($db);
// List of supported format
$tmptype2label = ExtraFields::$type2label;
$type2label = array('');
foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val);
foreach ($tmptype2label as $key => $val) {
$type2label[$key] = $langs->transnoentitiesnoconv($val);
}
$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'facture_rec'; //Must be the $table_element of the class that manage extrafield
if (!$user->admin) accessforbidden();
if (!$user->admin) {
accessforbidden();
}
/*
@ -78,8 +82,7 @@ print dol_get_fiche_end();
// Buttons
if ($action != 'create' && $action != 'edit')
{
if ($action != 'create' && $action != 'edit') {
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create#newattrib\">".$langs->trans("NewAttribute")."</a>";
print "</div>";
@ -92,8 +95,7 @@ if ($action != 'create' && $action != 'edit')
*
*/
if ($action == 'create')
{
if ($action == 'create') {
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
@ -105,8 +107,7 @@ if ($action == 'create')
* Edition of an optional field
*
*/
if ($action == 'edit' && !empty($attrname))
{
if ($action == 'edit' && !empty($attrname)) {
$langs->load("members");
print "<br>";

View File

@ -39,13 +39,17 @@ $form = new Form($db);
// List of supported format
$tmptype2label = ExtraFields::$type2label;
$type2label = array('');
foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val);
foreach ($tmptype2label as $key => $val) {
$type2label[$key] = $langs->transnoentitiesnoconv($val);
}
$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'facturedet'; //Must be the $table_element of the class that manage extrafield
if (!$user->admin) accessforbidden();
if (!$user->admin) {
accessforbidden();
}
/*
@ -78,8 +82,7 @@ print dol_get_fiche_end();
// Buttons
if ($action != 'create' && $action != 'edit')
{
if ($action != 'create' && $action != 'edit') {
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create#newattrib\">".$langs->trans("NewAttribute")."</a>";
print "</div>";
@ -92,8 +95,7 @@ if ($action != 'create' && $action != 'edit')
*
*/
if ($action == 'create')
{
if ($action == 'create') {
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
@ -105,8 +107,7 @@ if ($action == 'create')
* Edition d'un champ optionnel
*
*/
if ($action == 'edit' && !empty($attrname))
{
if ($action == 'edit' && !empty($attrname)) {
print "<br>";
print load_fiche_titre($langs->trans("FieldEdition", $attrname));

View File

@ -39,13 +39,17 @@ $form = new Form($db);
// List of supported format
$tmptype2label = ExtraFields::$type2label;
$type2label = array('');
foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val);
foreach ($tmptype2label as $key => $val) {
$type2label[$key] = $langs->transnoentitiesnoconv($val);
}
$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'facturedet_rec'; //Must be the $table_element of the class that manage extrafield
if (!$user->admin) accessforbidden();
if (!$user->admin) {
accessforbidden();
}
/*
@ -78,8 +82,7 @@ print dol_get_fiche_end();
// Buttons
if ($action != 'create' && $action != 'edit')
{
if ($action != 'create' && $action != 'edit') {
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create#newattrib\">".$langs->trans("NewAttribute")."</a>";
print "</div>";
@ -92,8 +95,7 @@ if ($action != 'create' && $action != 'edit')
*
*/
if ($action == 'create')
{
if ($action == 'create') {
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
@ -105,8 +107,7 @@ if ($action == 'create')
* Edition d'un champ optionnel
*
*/
if ($action == 'edit' && !empty($attrname))
{
if ($action == 'edit' && !empty($attrname)) {
print "<br>";
print load_fiche_titre($langs->trans("FieldEdition", $attrname));

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -172,35 +172,52 @@ class Invoices extends DolibarrApi
// If the internal user must only see his customers, force searching by him
$search_sale = 0;
if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) {
$search_sale = DolibarrApiAccess::$user->id;
}
$sql = "SELECT t.rowid";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
$sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
}
$sql .= " FROM ".MAIN_DB_PREFIX."facture as t";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
}
$sql .= ' WHERE t.entity IN ('.getEntity('invoice').')';
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc";
if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) {
$sql .= " AND t.fk_soc = sc.fk_soc";
}
if ($socids) {
$sql .= " AND t.fk_soc IN (".$socids.")";
}
if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
if ($search_sale > 0) {
$sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
}
// Filter by status
if ($status == 'draft') $sql .= " AND t.fk_statut IN (0)";
if ($status == 'unpaid') $sql .= " AND t.fk_statut IN (1)";
if ($status == 'paid') $sql .= " AND t.fk_statut IN (2)";
if ($status == 'cancelled') $sql .= " AND t.fk_statut IN (3)";
if ($status == 'draft') {
$sql .= " AND t.fk_statut IN (0)";
}
if ($status == 'unpaid') {
$sql .= " AND t.fk_statut IN (1)";
}
if ($status == 'paid') {
$sql .= " AND t.fk_statut IN (2)";
}
if ($status == 'cancelled') {
$sql .= " AND t.fk_statut IN (3)";
}
// Insert sale filter
if ($search_sale > 0)
{
if ($search_sale > 0) {
$sql .= " AND sc.fk_user = ".$search_sale;
}
// Add sql filters
if ($sqlfilters)
{
if (!DolibarrApi::_checkFilters($sqlfilters))
{
if ($sqlfilters) {
if (!DolibarrApi::_checkFilters($sqlfilters)) {
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
@ -208,10 +225,8 @@ class Invoices extends DolibarrApi
}
$sql .= $this->db->order($sortfield, $sortorder);
if ($limit)
{
if ($page < 0)
{
if ($limit) {
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
@ -220,17 +235,14 @@ class Invoices extends DolibarrApi
}
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$i = 0;
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
while ($i < $min)
{
while ($i < $min) {
$obj = $this->db->fetch_object($result);
$invoice_static = new Facture($this->db);
if ($invoice_static->fetch($obj->rowid))
{
if ($invoice_static->fetch($obj->rowid)) {
// Get payment details
$invoice_static->totalpaid = $invoice_static->getSommePaiement();
$invoice_static->totalcreditnotes = $invoice_static->getSumCreditNotesUsed();
@ -274,13 +286,13 @@ class Invoices extends DolibarrApi
$this->invoice->date = dol_now();
}
/* We keep lines as an array
if (isset($request_data["lines"])) {
$lines = array();
foreach ($request_data["lines"] as $line) {
array_push($lines, (object) $line);
}
$this->invoice->lines = $lines;
}*/
if (isset($request_data["lines"])) {
$lines = array();
foreach ($request_data["lines"] as $line) {
array_push($lines, (object) $line);
}
$this->invoice->lines = $lines;
}*/
if ($this->invoice->create(DolibarrApiAccess::$user, 0, (empty($request_data["date_lim_reglement"]) ? 0 : $request_data["date_lim_reglement"])) < 0) {
throw new RestException(500, "Error creating invoice", array_merge(array($this->invoice->error), $this->invoice->errors));
@ -585,20 +597,22 @@ class Invoices extends DolibarrApi
}
foreach ($request_data as $field => $value) {
if ($field == 'id') continue;
if ($field == 'id') {
continue;
}
$this->invoice->$field = $value;
}
// update bank account
if (!empty($this->invoice->fk_account))
{
if (!empty($this->invoice->fk_account)) {
if ($this->invoice->setBankAccount($this->invoice->fk_account) == 0) {
throw new RestException(400, $this->invoice->error);
}
}
if ($this->invoice->update(DolibarrApiAccess::$user))
if ($this->invoice->update(DolibarrApiAccess::$user)) {
return $this->get($id);
}
return false;
}
@ -624,8 +638,7 @@ class Invoices extends DolibarrApi
}
$result = $this->invoice->delete(DolibarrApiAccess::$user);
if ($result < 0)
{
if ($result < 0) {
throw new RestException(500);
}
@ -1062,10 +1075,13 @@ class Invoices extends DolibarrApi
$result = $discountcheck->fetch(0, $this->invoice->id);
$canconvert = 0;
if ($this->invoice->type == Facture::TYPE_DEPOSIT && empty($discountcheck->id)) $canconvert = 1; // we can convert deposit into discount if deposit is payed (completely, partially or not at all) and not already converted (see real condition into condition used to show button converttoreduc)
if (($this->invoice->type == Facture::TYPE_CREDIT_NOTE || $this->invoice->type == Facture::TYPE_STANDARD) && $this->invoice->paye == 0 && empty($discountcheck->id)) $canconvert = 1; // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc)
if ($canconvert)
{
if ($this->invoice->type == Facture::TYPE_DEPOSIT && empty($discountcheck->id)) {
$canconvert = 1; // we can convert deposit into discount if deposit is payed (completely, partially or not at all) and not already converted (see real condition into condition used to show button converttoreduc)
}
if (($this->invoice->type == Facture::TYPE_CREDIT_NOTE || $this->invoice->type == Facture::TYPE_STANDARD) && $this->invoice->paye == 0 && empty($discountcheck->id)) {
$canconvert = 1; // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc)
}
if ($canconvert) {
$this->db->begin();
$amount_ht = $amount_tva = $amount_ttc = array();
@ -1073,10 +1089,9 @@ class Invoices extends DolibarrApi
// Loop on each vat rate
$i = 0;
foreach ($this->invoice->lines as $line)
{
if ($line->product_type < 9 && $line->total_ht != 0) // Remove lines with product_type greater than or equal to 9
{ // no need to create discount if amount is null
foreach ($this->invoice->lines as $line) {
if ($line->product_type < 9 && $line->total_ht != 0) { // Remove lines with product_type greater than or equal to 9
// no need to create discount if amount is null
$amount_ht[$line->tva_tx] += $line->total_ht;
$amount_tva[$line->tva_tx] += $line->total_tva;
$amount_ttc[$line->tva_tx] += $line->total_ttc;
@ -1104,8 +1119,7 @@ class Invoices extends DolibarrApi
$error = 0;
if ($this->invoice->type == Facture::TYPE_STANDARD || $this->invoice->type == Facture::TYPE_REPLACEMENT || $this->invoice->type == Facture::TYPE_SITUATION)
{
if ($this->invoice->type == Facture::TYPE_STANDARD || $this->invoice->type == Facture::TYPE_REPLACEMENT || $this->invoice->type == Facture::TYPE_SITUATION) {
// If we're on a standard invoice, we have to get excess received to create a discount in TTC without VAT
// Total payments
@ -1116,7 +1130,9 @@ class Invoices extends DolibarrApi
$sql .= ' AND pf.fk_paiement = p.rowid';
$sql .= ' AND p.entity IN ('.getEntity('invoice').')';
$resql = $this->db->query($sql);
if (!$resql) dol_print_error($this->db);
if (!$resql) {
dol_print_error($this->db);
}
$res = $this->db->fetch_object($resql);
$total_payments = $res->total_payments;
@ -1129,23 +1145,24 @@ class Invoices extends DolibarrApi
$sql .= " WHERE fk_facture = ".$this->invoice->id;
$resql = $this->db->query($sql);
if (!empty($resql)) {
while ($obj = $this->db->fetch_object($resql)) $total_creditnote_and_deposit += $obj->amount_ttc;
} else dol_print_error($this->db);
while ($obj = $this->db->fetch_object($resql)) {
$total_creditnote_and_deposit += $obj->amount_ttc;
}
} else {
dol_print_error($this->db);
}
$discount->amount_ht = $discount->amount_ttc = $total_payments + $total_creditnote_and_deposit - $this->invoice->total_ttc;
$discount->amount_tva = 0;
$discount->tva_tx = 0;
$result = $discount->create(DolibarrApiAccess::$user);
if ($result < 0)
{
if ($result < 0) {
$error++;
}
}
if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE || $this->invoice->type == Facture::TYPE_DEPOSIT)
{
foreach ($amount_ht as $tva_tx => $xxx)
{
if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE || $this->invoice->type == Facture::TYPE_DEPOSIT) {
foreach ($amount_ht as $tva_tx => $xxx) {
$discount->amount_ht = abs($amount_ht[$tva_tx]);
$discount->amount_tva = abs($amount_tva[$tva_tx]);
$discount->amount_ttc = abs($amount_ttc[$tva_tx]);
@ -1155,21 +1172,18 @@ class Invoices extends DolibarrApi
$discount->tva_tx = abs($tva_tx);
$result = $discount->create(DolibarrApiAccess::$user);
if ($result < 0)
{
if ($result < 0) {
$error++;
break;
}
}
}
if (empty($error))
{
if (empty($error)) {
if ($this->invoice->type != Facture::TYPE_DEPOSIT) {
// Classe facture
$result = $this->invoice->setPaid(DolibarrApiAccess::$user);
if ($result >= 0)
{
if ($result >= 0) {
$this->db->commit();
} else {
$this->db->rollback();
@ -1417,8 +1431,7 @@ class Invoices extends DolibarrApi
$paymentobj->note_private = $comment;
$payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices
if ($payment_id < 0)
{
if ($payment_id < 0) {
$this->db->rollback();
throw new RestException(400, 'Payment error : '.$paymentobj->error);
}
@ -1429,10 +1442,11 @@ class Invoices extends DolibarrApi
if ($paymentobj->paiementcode == 'CHQ' && empty($chqemetteur)) {
throw new RestException(400, 'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
}
if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) {
$label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
}
$result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user, 'payment', $label, $accountid, $chqemetteur, $chqbank);
if ($result < 0)
{
if ($result < 0) {
$this->db->rollback();
throw new RestException(400, 'Add payment to bank error : '.$paymentobj->error);
}
@ -1501,8 +1515,7 @@ class Invoices extends DolibarrApi
$multicurrency_amounts = array();
// Loop on each invoice to pay
foreach ($arrayofamounts as $id => $amountarray)
{
foreach ($arrayofamounts as $id => $amountarray) {
$result = $this->invoice->fetch($id);
if (!$result) {
$this->db->rollback();
@ -1528,13 +1541,11 @@ class Invoices extends DolibarrApi
$totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency);
$remainstopay = $amount = price2num($total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
if (!$is_multicurrency && $amountarray["amount"] != 'remain')
{
if (!$is_multicurrency && $amountarray["amount"] != 'remain') {
$amount = price2num($amountarray["amount"], 'MT');
}
if ($is_multicurrency && $amountarray["multicurrency_amount"] != 'remain')
{
if ($is_multicurrency && $amountarray["multicurrency_amount"] != 'remain') {
$amount = price2num($amountarray["multicurrency_amount"], 'MT');
}
@ -1569,8 +1580,7 @@ class Invoices extends DolibarrApi
$paymentobj->note_private = $comment;
$paymentobj->ref_ext = $ref_ext;
$payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices
if ($payment_id < 0)
{
if ($payment_id < 0) {
$this->db->rollback();
throw new RestException(400, 'Payment error : '.$paymentobj->error);
}
@ -1579,10 +1589,11 @@ class Invoices extends DolibarrApi
if ($paymentobj->paiementcode == 'CHQ' && empty($chqemetteur)) {
throw new RestException(400, 'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode);
}
if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) {
$label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
}
$result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user, 'payment', $label, $accountid, $chqemetteur, $chqbank);
if ($result < 0)
{
if ($result < 0) {
$this->db->rollback();
throw new RestException(400, 'Add payment to bank error : '.$paymentobj->error);
}

View File

@ -218,11 +218,12 @@ class FactureRec extends CommonInvoice
$this->titre = trim(isset($this->titre) ? $this->titre : $this->title); // deprecated
$this->title = trim($this->title);
$this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
if (empty($this->suspended)) $this->suspended = 0;
if (empty($this->suspended)) {
$this->suspended = 0;
}
// No frequency defined then no next date to execution
if (empty($this->frequency))
{
if (empty($this->frequency)) {
$this->frequency = 0;
$this->date_when = null;
}
@ -238,8 +239,7 @@ class FactureRec extends CommonInvoice
// Charge facture modele
$facsrc = new Facture($this->db);
$result = $facsrc->fetch($facid);
if ($result > 0)
{
if ($result > 0) {
// On positionne en mode brouillon la facture
$this->brouillon = 1;
@ -301,8 +301,7 @@ class FactureRec extends CommonInvoice
$sql .= ", ".$this->db->escape($this->suspended);
$sql .= ")";
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
// Fields used into addline later
@ -312,10 +311,11 @@ class FactureRec extends CommonInvoice
// Add lines
$num = count($facsrc->lines);
for ($i = 0; $i < $num; $i++)
{
for ($i = 0; $i < $num; $i++) {
$tva_tx = $facsrc->lines[$i]->tva_tx;
if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$facsrc->lines[$i]->vat_src_code.')';
if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match('/\(/', $tva_tx)) {
$tva_tx .= ' ('.$facsrc->lines[$i]->vat_src_code.')';
}
$result_insert = $this->addline(
$facsrc->lines[$i]->desc,
@ -338,13 +338,11 @@ class FactureRec extends CommonInvoice
$facsrc->lines[$i]->multicurrency_subprice
);
if ($result_insert < 0)
{
if ($result_insert < 0) {
$error++;
} else {
$objectline = new FactureLigneRec($this->db);
if ($objectline->fetch($result_insert))
{
if ($objectline->fetch($result_insert)) {
// Extrafields
if (method_exists($facsrc->lines[$i], 'fetch_optionals')) {
$facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id);
@ -352,31 +350,24 @@ class FactureRec extends CommonInvoice
}
$result = $objectline->insertExtraFields();
if ($result < 0)
{
if ($result < 0) {
$error++;
}
}
}
}
if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects
{
if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
$this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
}
// Add object linked
if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects))
{
foreach ($this->linked_objects as $origin => $tmp_origin_id)
{
if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
{
foreach ($tmp_origin_id as $origin_id)
{
if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
foreach ($this->linked_objects as $origin => $tmp_origin_id) {
if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
foreach ($tmp_origin_id as $origin_id) {
$ret = $this->add_object_linked($origin, $origin_id);
if (!$ret)
{
if (!$ret) {
$this->error = $this->db->lasterror();
$error++;
}
@ -385,8 +376,7 @@ class FactureRec extends CommonInvoice
{
$origin_id = $tmp_origin_id;
$ret = $this->add_object_linked($origin, $origin_id);
if (!$ret)
{
if (!$ret) {
$this->error = $this->db->lasterror();
$error++;
}
@ -396,26 +386,22 @@ class FactureRec extends CommonInvoice
if (!$error) {
$result = $this->insertExtraFields();
if ($result < 0)
{
if ($result < 0) {
$error++;
}
}
if (!$error && !$notrigger)
{
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('BILLREC_CREATE', $user);
if ($result < 0)
{
if ($result < 0) {
$this->db->rollback();
return -2;
}
// End call triggers
}
if ($error)
{
if ($error) {
$this->db->rollback();
} else {
$this->db->commit();
@ -453,23 +439,18 @@ class FactureRec extends CommonInvoice
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if (!$error)
{
if ($resql) {
if (!$error) {
$result = $this->insertExtraFields();
if ($result < 0)
{
if ($result < 0) {
$error++;
}
}
if (!$error && !$notrigger)
{
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('BILLREC_UPDATE', $user);
if ($result < 0)
{
if ($result < 0) {
$this->db->rollback();
return -2;
}
@ -512,18 +493,19 @@ class FactureRec extends CommonInvoice
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'";
$sql .= ' WHERE f.entity IN ('.getEntity('invoice').')';
if ($rowid) $sql .= ' AND f.rowid='.$rowid;
elseif ($ref) $sql .= " AND f.titre='".$this->db->escape($ref)."'";
if ($rowid) {
$sql .= ' AND f.rowid='.$rowid;
} elseif ($ref) {
$sql .= " AND f.titre='".$this->db->escape($ref)."'";
}
/* This field are not used for template invoice
if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
if ($ref_int) $sql.= " AND f.ref_int='".$this->db->escape($ref_int)."'";
*/
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
@ -584,7 +566,9 @@ class FactureRec extends CommonInvoice
$this->multicurrency_total_tva = $obj->multicurrency_total_tva;
$this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;
if ($this->statut == self::STATUS_DRAFT) {
$this->brouillon = 1;
}
// Retrieve all extrafield
// fetch optionals attributes and labels
@ -594,8 +578,7 @@ class FactureRec extends CommonInvoice
* Lines
*/
$result = $this->fetch_lines();
if ($result < 0)
{
if ($result < 0) {
$this->error = $this->db->lasterror();
return -3;
}
@ -638,8 +621,7 @@ class FactureRec extends CommonInvoice
// Retrieve all extrafield for line
// fetch optionals attributes and labels
if (!is_object($extrafields))
{
if (!is_object($extrafields)) {
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
}
@ -662,12 +644,10 @@ class FactureRec extends CommonInvoice
dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $this->db->fetch_object($result);
$line = new FactureLigneRec($this->db);
@ -764,18 +744,20 @@ class FactureRec extends CommonInvoice
dol_syslog($sqlef);
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".$rowid;
dol_syslog($sql);
if ($this->db->query($sqlef) && $this->db->query($sql))
{
if ($this->db->query($sqlef) && $this->db->query($sql)) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = ".$rowid;
dol_syslog($sql);
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
// Delete linked object
$res = $this->deleteObjectLinked();
if ($res < 0) $error = -3;
if ($res < 0) {
$error = -3;
}
// Delete extrafields
$res = $this->deleteExtraFields();
if ($res < 0) $error = -4;
if ($res < 0) {
$error = -4;
}
} else {
$this->error = $this->db->lasterror();
$error = -1;
@ -785,8 +767,7 @@ class FactureRec extends CommonInvoice
$error = -2;
}
if (!$error)
{
if (!$error) {
$this->db->commit();
return 1;
} else {
@ -833,23 +814,25 @@ class FactureRec extends CommonInvoice
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Check parameters
if ($type < 0) return -1;
if ($type < 0) {
return -1;
}
$localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
// Clean vat code
$vat_src_code = '';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
if (preg_match('/\((.*)\)/', $txtva, $reg)) {
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
if ($this->brouillon)
{
if ($this->brouillon) {
// Clean parameters
$remise_percent = price2num($remise_percent);
if (empty($remise_percent)) $remise_percent = 0;
if (empty($remise_percent)) {
$remise_percent = 0;
}
$qty = price2num($qty);
$pu_ht = price2num($pu_ht);
$pu_ttc = price2num($pu_ttc);
@ -858,13 +841,20 @@ class FactureRec extends CommonInvoice
}
$txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2);
if (empty($txtva)) $txtva = 0;
if (empty($txlocaltax1)) $txlocaltax1 = 0;
if (empty($txlocaltax2)) $txlocaltax2 = 0;
if (empty($info_bits)) $info_bits = 0;
if (empty($txtva)) {
$txtva = 0;
}
if (empty($txlocaltax1)) {
$txlocaltax1 = 0;
}
if (empty($txlocaltax2)) {
$txlocaltax2 = 0;
}
if (empty($info_bits)) {
$info_bits = 0;
}
if ($price_base_type == 'HT')
{
if ($price_base_type == 'HT') {
$pu = $pu_ht;
} else {
$pu = $pu_ttc;
@ -890,8 +880,7 @@ class FactureRec extends CommonInvoice
$pu_ht_devise = $tabprice[19];
$product_type = $type;
if ($fk_product)
{
if ($fk_product) {
$product = new Product($this->db);
$result = $product->fetch($fk_product);
$product_type = $product->type;
@ -967,8 +956,7 @@ class FactureRec extends CommonInvoice
$sql .= ")";
dol_syslog(get_class($this)."::addline", LOG_DEBUG);
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$lineId = $this->db->last_insert_id(MAIN_DB_PREFIX."facturedet_rec");
$this->id = $facid;
$this->update_price();
@ -1019,35 +1007,51 @@ class FactureRec extends CommonInvoice
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Clean parameters
if (empty($remise_percent)) $remise_percent = 0;
if (empty($remise_percent)) {
$remise_percent = 0;
}
// Check parameters
if ($type < 0) return -1;
if ($type < 0) {
return -1;
}
if ($this->brouillon)
{
if ($this->brouillon) {
// Clean parameters
$remise_percent = price2num($remise_percent);
$qty = price2num($qty);
if (empty($info_bits)) $info_bits = 0;
if (empty($info_bits)) {
$info_bits = 0;
}
$pu_ht = price2num($pu_ht);
$pu_ttc = price2num($pu_ttc);
$pu_ht_devise = price2num($pu_ht_devise);
if (!preg_match('/\((.*)\)/', $txtva)) {
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
}
if (!preg_match('/\((.*)\)/', $txtva)) {
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
}
$txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2);
if (empty($txlocaltax1)) $txlocaltax1 = 0;
if (empty($txlocaltax2)) $txlocaltax2 = 0;
if (empty($txlocaltax1)) {
$txlocaltax1 = 0;
}
if (empty($txlocaltax2)) {
$txlocaltax2 = 0;
}
if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice = 0;
if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht = 0;
if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva = 0;
if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc = 0;
if (empty($this->multicurrency_subprice)) {
$this->multicurrency_subprice = 0;
}
if (empty($this->multicurrency_total_ht)) {
$this->multicurrency_total_ht = 0;
}
if (empty($this->multicurrency_total_tva)) {
$this->multicurrency_total_tva = 0;
}
if (empty($this->multicurrency_total_ttc)) {
$this->multicurrency_total_ttc = 0;
}
if ($price_base_type == 'HT')
{
if ($price_base_type == 'HT') {
$pu = $pu_ht;
} else {
$pu = $pu_ttc;
@ -1061,9 +1065,8 @@ class FactureRec extends CommonInvoice
// Clean vat code
$vat_src_code = '';
$reg = array();
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$reg = array();
if (preg_match('/\((.*)\)/', $txtva, $reg)) {
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
@ -1086,8 +1089,7 @@ class FactureRec extends CommonInvoice
$pu_ht_devise = $tabprice[19];
$product_type = $type;
if ($fk_product)
{
if ($fk_product) {
$product = new Product($this->db);
$result = $product->fetch($fk_product);
$product_type = $product->type;
@ -1129,8 +1131,7 @@ class FactureRec extends CommonInvoice
$sql .= " WHERE rowid = ".$rowid;
dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$this->id = $facid;
$this->update_price();
return 1;
@ -1149,7 +1150,9 @@ class FactureRec extends CommonInvoice
*/
public function getNextDate()
{
if (empty($this->date_when)) return false;
if (empty($this->date_when)) {
return false;
}
return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
}
@ -1161,7 +1164,9 @@ class FactureRec extends CommonInvoice
public function isMaxNbGenReached()
{
$ret = false;
if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) $ret = true;
if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
$ret = true;
}
return $ret;
}
@ -1209,8 +1214,9 @@ class FactureRec extends CommonInvoice
$sql .= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
$sql .= ' AND suspended = 0';
$sql .= ' AND entity = '.$conf->entity; // MUST STAY = $conf->entity here
if ($restrictioninvoiceid > 0)
if ($restrictioninvoiceid > 0) {
$sql .= ' AND rowid = '.$restrictioninvoiceid;
}
$sql .= $this->db->order('entity', 'ASC');
//print $sql;exit;
$parameters = array(
@ -1220,19 +1226,19 @@ class FactureRec extends CommonInvoice
$reshook = $hookmanager->executeHooks('beforeCreationOfRecurringInvoices', $parameters, $sql); // note that $sql might be modified by hooks
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$i = 0;
$num = $this->db->num_rows($resql);
if ($num)
if ($num) {
$this->output .= $langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
else $this->output .= $langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
} else {
$this->output .= $langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
}
$saventity = $conf->entity;
while ($i < $num) // Loop on each template invoice. If $num = 0, test is false at first pass.
{
while ($i < $num) { // Loop on each template invoice. If $num = 0, test is false at first pass.
$line = $this->db->fetch_object($resql);
$this->db->begin();
@ -1243,8 +1249,7 @@ class FactureRec extends CommonInvoice
$facturerec = new FactureRec($this->db);
$facturerec->fetch($line->rowid);
if ($facturerec->id > 0)
{
if ($facturerec->id > 0) {
// Set entity context
$conf->entity = $facturerec->entity;
@ -1260,24 +1265,20 @@ class FactureRec extends CommonInvoice
$facture->socid = $facturerec->socid;
$invoiceidgenerated = $facture->create($user);
if ($invoiceidgenerated <= 0)
{
if ($invoiceidgenerated <= 0) {
$this->errors = $facture->errors;
$this->error = $facture->error;
$error++;
}
if (!$error && ($facturerec->auto_validate || $forcevalidation))
{
if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
$result = $facture->validate($user);
if ($result <= 0)
{
if ($result <= 0) {
$this->errors = $facture->errors;
$this->error = $facture->error;
$error++;
}
}
if (!$error && $facturerec->generate_pdf)
{
if (!$error && $facturerec->generate_pdf) {
// We refresh the object in order to have all necessary data (like date_lim_reglement)
$facture->fetch($facture->id);
$result = $facture->generateDocument($facturerec->model_pdf, $langs);
@ -1294,8 +1295,7 @@ class FactureRec extends CommonInvoice
dol_syslog("createRecurringInvoices Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity);
}
if (!$error && $invoiceidgenerated >= 0)
{
if (!$error && $invoiceidgenerated >= 0) {
$this->db->commit("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
dol_syslog("createRecurringInvoices Process invoice template ".$facturerec->ref." is finished with a success generation");
$nb_create++;
@ -1318,7 +1318,9 @@ class FactureRec extends CommonInvoice
}
$conf->entity = $saventity; // Restore entity context
} else dol_print_error($this->db);
} else {
dol_print_error($this->db);
}
$this->output = trim($this->output);
@ -1357,28 +1359,39 @@ class FactureRec extends CommonInvoice
if (!empty($this->date_when)) {
$label .= '<br><b>'.$langs->trans('NextDateToExecution').':</b> ';
$label .= (empty($this->suspended) ? '' : '<strike>').dol_print_date($this->date_when, 'day').(empty($this->suspended) ? '' : '</strike>'); // No hour for this property
if (!empty($this->suspended)) $label .= ' ('.$langs->trans("Disabled").')';
if (!empty($this->suspended)) {
$label .= ' ('.$langs->trans("Disabled").')';
}
}
}
$url = DOL_URL_ROOT.'/compta/facture/card-rec.php?facid='.$this->id;
if ($short) return $url;
if ($short) {
return $url;
}
if ($option != 'nolink')
{
if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
$add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
}
$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
if ($withpicto) {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto != 2) {
$result .= $this->ref;
}
$result .= $linkend;
return $result;
@ -1417,11 +1430,9 @@ class FactureRec extends CommonInvoice
$statusType = 'status0';
//print "$recur,$status,$mode,$alreadypaid,$type";
if ($mode == 0)
{
if ($mode == 0) {
$prefix = '';
if ($recur)
{
if ($recur) {
if ($status == self::STATUS_SUSPENDED) {
$labelStatus = $langs->trans('Disabled');
} else {
@ -1434,11 +1445,9 @@ class FactureRec extends CommonInvoice
$labelStatus = $langs->trans("Draft");
}
}
} elseif ($mode == 1)
{
} elseif ($mode == 1) {
$prefix = 'Short';
if ($recur)
{
if ($recur) {
if ($status == self::STATUS_SUSPENDED) {
$labelStatus = $langs->trans('Disabled');
} else {
@ -1451,10 +1460,8 @@ class FactureRec extends CommonInvoice
$labelStatus = $langs->trans("Draft");
}
}
} elseif ($mode == 2)
{
if ($recur)
{
} elseif ($mode == 2) {
if ($recur) {
if ($status == self::STATUS_SUSPENDED) {
$statusType = 'status6';
$labelStatus = $langs->trans('Disabled');
@ -1471,10 +1478,8 @@ class FactureRec extends CommonInvoice
$labelStatus = $langs->trans('Draft');
}
}
} elseif ($mode == 3)
{
if ($recur)
{
} elseif ($mode == 3) {
if ($recur) {
$prefix = 'Short';
if ($status == self::STATUS_SUSPENDED) {
$statusType = 'status6';
@ -1492,11 +1497,9 @@ class FactureRec extends CommonInvoice
$labelStatus = $langs->trans('Draft');
}
}
} elseif ($mode == 4)
{
} elseif ($mode == 4) {
$prefix = '';
if ($recur)
{
if ($recur) {
if ($status == self::STATUS_SUSPENDED) {
$statusType = 'status6';
$labelStatus = $langs->trans('Disabled');
@ -1513,12 +1516,12 @@ class FactureRec extends CommonInvoice
$labelStatus = $langs->trans('Draft');
}
}
} elseif ($mode == 5 || $mode == 6)
{
} elseif ($mode == 5 || $mode == 6) {
$prefix = '';
if ($mode == 5) $prefix = 'Short';
if ($recur)
{
if ($mode == 5) {
$prefix = 'Short';
}
if ($recur) {
if ($status == self::STATUS_SUSPENDED) {
$statusType = 'status6';
$labelStatus = $langs->trans('Disabled');
@ -1537,7 +1540,9 @@ class FactureRec extends CommonInvoice
}
}
if (empty($labelStatusShort)) $labelStatusShort = $labelStatus;
if (empty($labelStatusShort)) {
$labelStatusShort = $labelStatus;
}
return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
}
@ -1568,12 +1573,10 @@ class FactureRec extends CommonInvoice
$sql .= $this->db->plimit(100);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num_prods = $this->db->num_rows($resql);
$i = 0;
while ($i < $num_prods)
{
while ($i < $num_prods) {
$i++;
$row = $this->db->fetch_row($resql);
$prodids[$i] = $row[0];
@ -1598,13 +1601,11 @@ class FactureRec extends CommonInvoice
$this->fk_incoterms = 0;
$this->location_incoterms = '';
if (empty($option) || $option != 'nolines')
{
if (empty($option) || $option != 'nolines') {
// Lines
$nbp = 5;
$xnbp = 0;
while ($xnbp < $nbp)
{
while ($xnbp < $nbp) {
$line = new FactureLigne($this->db);
$line->desc = $langs->trans("Description")." ".$xnbp;
$line->qty = 1;
@ -1613,23 +1614,20 @@ class FactureRec extends CommonInvoice
$line->localtax1_tx = 0;
$line->localtax2_tx = 0;
$line->remise_percent = 0;
if ($xnbp == 1) // Qty is negative (product line)
{
if ($xnbp == 1) { // Qty is negative (product line)
$prodid = mt_rand(1, $num_prods);
$line->fk_product = $prodids[$prodid];
$line->qty = -1;
$line->total_ht = -100;
$line->total_ttc = -119.6;
$line->total_tva = -19.6;
} elseif ($xnbp == 2) // UP is negative (free line)
{
} elseif ($xnbp == 2) { // UP is negative (free line)
$line->subprice = -100;
$line->total_ht = -100;
$line->total_ttc = -119.6;
$line->total_tva = -19.6;
$line->remise_percent = 0;
} elseif ($xnbp == 3) // Discount is 50% (product line)
{
} elseif ($xnbp == 3) { // Discount is 50% (product line)
$prodid = mt_rand(1, $num_prods);
$line->fk_product = $prodids[$prodid];
$line->total_ht = 50;
@ -1723,7 +1721,9 @@ class FactureRec extends CommonInvoice
dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
if ($this->db->query($sql)) {
$this->frequency = $frequency;
if (!empty($unit)) $this->unit_frequency = $unit;
if (!empty($unit)) {
$this->unit_frequency = $unit;
}
return 1;
} else {
dol_print_error($this->db);
@ -1740,21 +1740,23 @@ class FactureRec extends CommonInvoice
*/
public function setNextDate($date, $increment_nb_gen_done = 0)
{
if (!$this->table_element)
{
if (!$this->table_element) {
dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined", LOG_ERR);
return -1;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
if ($increment_nb_gen_done > 0) $sql .= ', nb_gen_done = nb_gen_done + 1';
if ($increment_nb_gen_done > 0) {
$sql .= ', nb_gen_done = nb_gen_done + 1';
}
$sql .= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$this->date_when = $date;
if ($increment_nb_gen_done > 0) $this->nb_gen_done++;
if ($increment_nb_gen_done > 0) {
$this->nb_gen_done++;
}
return 1;
} else {
dol_print_error($this->db);
@ -1770,21 +1772,21 @@ class FactureRec extends CommonInvoice
*/
public function setMaxPeriod($nb)
{
if (!$this->table_element)
{
if (!$this->table_element) {
dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
return -1;
}
if (empty($nb)) $nb = 0;
if (empty($nb)) {
$nb = 0;
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql .= ' SET nb_gen_max = '.$nb;
$sql .= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$this->nb_gen_max = $nb;
return 1;
} else {
@ -1801,8 +1803,7 @@ class FactureRec extends CommonInvoice
*/
public function setAutoValidate($validate)
{
if (!$this->table_element)
{
if (!$this->table_element) {
dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined", LOG_ERR);
return -1;
}
@ -1812,8 +1813,7 @@ class FactureRec extends CommonInvoice
$sql .= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$this->auto_validate = $validate;
return 1;
} else {
@ -1830,8 +1830,7 @@ class FactureRec extends CommonInvoice
*/
public function setGeneratePdf($validate)
{
if (!$this->table_element)
{
if (!$this->table_element) {
dol_syslog(get_class($this)."::setGeneratePdf was called on objet with property table_element not defined", LOG_ERR);
return -1;
}
@ -1841,8 +1840,7 @@ class FactureRec extends CommonInvoice
$sql .= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::setGeneratePdf", LOG_DEBUG);
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$this->generate_pdf = $validate;
return 1;
} else {
@ -1859,8 +1857,7 @@ class FactureRec extends CommonInvoice
*/
public function setModelPdf($model)
{
if (!$this->table_element)
{
if (!$this->table_element) {
dol_syslog(get_class($this)."::setModelPdf was called on objet with property table_element not defined", LOG_ERR);
return -1;
}
@ -1870,8 +1867,7 @@ class FactureRec extends CommonInvoice
$sql .= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::setModelPdf", LOG_DEBUG);
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$this->model_pdf = $model;
return 1;
} else {
@ -1918,21 +1914,21 @@ class FactureLigneRec extends CommonInvoiceLine
if (!$notrigger) {
// Call triggers
$result = $this->call_trigger('LINEBILLREC_DELETE', $user);
if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail
if ($result < 0) {
$error++;
} // Do also here what you must do to rollback action if trigger fail
// End call triggers
}
}
if (!$error)
{
if (!$error) {
$result = $this->deleteExtraFields();
if ($result < 0) {
$error++;
}
}
if (!$error)
{
if (!$error) {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id;
$res = $this->db->query($sql);
@ -1974,8 +1970,7 @@ class FactureLigneRec extends CommonInvoiceLine
dol_syslog('FactureRec::fetch', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$objp = $this->db->fetch_object($result);
$this->id = $objp->rowid;
@ -2075,23 +2070,18 @@ class FactureLigneRec extends CommonInvoiceLine
dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if (!$error)
{
if ($resql) {
if (!$error) {
$result = $this->insertExtraFields();
if ($result < 0)
{
if ($result < 0) {
$error++;
}
}
if (!$error && !$notrigger)
{
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('LINEBILLREC_UPDATE', $user);
if ($result < 0)
{
if ($result < 0) {
$error++;
}
// End call triggers

File diff suppressed because it is too large Load Diff

View File

@ -67,16 +67,14 @@ class FactureStats extends Stats
$this->cachefilesuffix = $mode;
$this->join = '';
if ($mode == 'customer')
{
if ($mode == 'customer') {
$object = new Facture($this->db);
$this->from = MAIN_DB_PREFIX.$object->table_element." as f";
$this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl";
$this->field = 'total';
$this->field_line = 'total_ht';
}
if ($mode == 'supplier')
{
if ($mode == 'supplier') {
$object = new FactureFournisseur($this->db);
$this->from = MAIN_DB_PREFIX.$object->table_element." as f";
$this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl";
@ -87,24 +85,30 @@ class FactureStats extends Stats
$this->where = " f.fk_statut >= 0";
$this->where .= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($mode == 'customer') $this->where .= " AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons)
if ($this->socid)
{
if (!$user->rights->societe->client->voir && !$this->socid) {
$this->where .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($mode == 'customer') {
$this->where .= " AND (f.fk_statut <> 3 OR f.close_code <> 'replaced')"; // Exclude replaced invoices as they are duplicated (we count closed invoices for other reasons)
}
if ($this->socid) {
$this->where .= " AND f.fk_soc = ".$this->socid;
}
if ($this->userid > 0) $this->where .= ' AND f.fk_user_author = '.$this->userid;
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $this->where .= " AND f.type IN (0,1,2,5)";
else $this->where .= " AND f.type IN (0,1,2,3,5)";
if ($this->userid > 0) {
$this->where .= ' AND f.fk_user_author = '.$this->userid;
}
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$this->where .= " AND f.type IN (0,1,2,5)";
} else {
$this->where .= " AND f.type IN (0,1,2,3,5)";
}
if ($typentid)
{
if ($typentid) {
$this->join .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = f.fk_soc';
$this->where .= ' AND s.fk_typent = '.$typentid;
}
if ($categid)
{
if ($categid) {
$this->join .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_societe as cs ON cs.fk_soc = f.fk_soc';
$this->join .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as c ON c.rowid = cs.fk_categorie';
$this->where .= ' AND c.rowid = '.$categid;
@ -125,7 +129,9 @@ class FactureStats extends Stats
$sql = "SELECT date_format(f.datef,'%m') as dm, COUNT(*) as nb";
$sql .= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$this->socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= $this->join;
$sql .= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
$sql .= " AND ".$this->where;
@ -149,7 +155,9 @@ class FactureStats extends Stats
$sql = "SELECT date_format(f.datef,'%Y') as dm, COUNT(*), SUM(c.".$this->field.")";
$sql .= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$this->socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= $this->join;
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY dm";
@ -172,7 +180,9 @@ class FactureStats extends Stats
$sql = "SELECT date_format(datef,'%m') as dm, SUM(f.".$this->field.")";
$sql .= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$this->socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= $this->join;
$sql .= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
$sql .= " AND ".$this->where;
@ -196,7 +206,9 @@ class FactureStats extends Stats
$sql = "SELECT date_format(datef,'%m') as dm, AVG(f.".$this->field.")";
$sql .= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$this->socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= $this->join;
$sql .= " WHERE f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'";
$sql .= " AND ".$this->where;
@ -217,7 +229,9 @@ class FactureStats extends Stats
$sql = "SELECT date_format(datef,'%Y') as year, COUNT(*) as nb, SUM(f.".$this->field.") as total, AVG(f.".$this->field.") as avg";
$sql .= " FROM ".$this->from;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$this->socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= $this->join;
$sql .= " WHERE ".$this->where;
$sql .= " GROUP BY year";
@ -239,7 +253,9 @@ class FactureStats extends Stats
$sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg";
$sql .= " FROM ".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product";
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$this->socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= $this->join;
$sql .= " WHERE ".$this->where;
$sql .= " AND f.rowid = tl.fk_facture AND tl.fk_product = product.rowid";

View File

@ -88,14 +88,30 @@ class PaymentTerm // extends CommonObject
// Clean parameters
if (isset($this->code)) $this->code = trim($this->code);
if (isset($this->sortorder)) $this->sortorder = trim($this->sortorder);
if (isset($this->active)) $this->active = trim($this->active);
if (isset($this->libelle)) $this->libelle = trim($this->libelle);
if (isset($this->libelle_facture)) $this->libelle_facture = trim($this->libelle_facture);
if (isset($this->type_cdr)) $this->type_cdr = trim($this->type_cdr);
if (isset($this->nbjour)) $this->nbjour = trim($this->nbjour);
if (isset($this->decalage)) $this->decalage = trim($this->decalage);
if (isset($this->code)) {
$this->code = trim($this->code);
}
if (isset($this->sortorder)) {
$this->sortorder = trim($this->sortorder);
}
if (isset($this->active)) {
$this->active = trim($this->active);
}
if (isset($this->libelle)) {
$this->libelle = trim($this->libelle);
}
if (isset($this->libelle_facture)) {
$this->libelle_facture = trim($this->libelle_facture);
}
if (isset($this->type_cdr)) {
$this->type_cdr = trim($this->type_cdr);
}
if (isset($this->nbjour)) {
$this->nbjour = trim($this->nbjour);
}
if (isset($this->decalage)) {
$this->decalage = trim($this->decalage);
}
// Check parameters
@ -126,20 +142,19 @@ class PaymentTerm // extends CommonObject
$this->db->begin();
dol_syslog(get_class($this)."::create", LOG_DEBUG);
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
if (!$error)
{
if (!$error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_payment_term");
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -180,10 +195,8 @@ class PaymentTerm // extends CommonObject
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -201,7 +214,7 @@ class PaymentTerm // extends CommonObject
return 1;
} else {
$this->error = "Error ".$this->db->lasterror();
$this->error = "Error ".$this->db->lasterror();
return -1;
}
}
@ -226,12 +239,12 @@ class PaymentTerm // extends CommonObject
dol_syslog(get_class($this)."::getDefaultId", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
if ($obj) $ret = $obj->rowid;
if ($obj) {
$ret = $obj->rowid;
}
}
$this->db->free($resql);
return $ret;
@ -257,14 +270,30 @@ class PaymentTerm // extends CommonObject
// Clean parameters
if (isset($this->code)) $this->code = trim($this->code);
if (isset($this->sortorder)) $this->sortorder = trim($this->sortorder);
if (isset($this->active)) $this->active = trim($this->active);
if (isset($this->libelle)) $this->libelle = trim($this->libelle);
if (isset($this->libelle_facture)) $this->libelle_facture = trim($this->libelle_facture);
if (isset($this->type_cdr)) $this->type_cdr = trim($this->type_cdr);
if (isset($this->nbjour)) $this->nbjour = trim($this->nbjour);
if (isset($this->decalage)) $this->decalage = trim($this->decalage);
if (isset($this->code)) {
$this->code = trim($this->code);
}
if (isset($this->sortorder)) {
$this->sortorder = trim($this->sortorder);
}
if (isset($this->active)) {
$this->active = trim($this->active);
}
if (isset($this->libelle)) {
$this->libelle = trim($this->libelle);
}
if (isset($this->libelle_facture)) {
$this->libelle_facture = trim($this->libelle_facture);
}
if (isset($this->type_cdr)) {
$this->type_cdr = trim($this->type_cdr);
}
if (isset($this->nbjour)) {
$this->nbjour = trim($this->nbjour);
}
if (isset($this->decalage)) {
$this->decalage = trim($this->decalage);
}
@ -287,13 +316,13 @@ class PaymentTerm // extends CommonObject
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -325,13 +354,13 @@ class PaymentTerm // extends CommonObject
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
// Commit or rollback
if ($error)
{
foreach ($this->errors as $errmsg)
{
if ($error) {
foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
@ -373,8 +402,7 @@ class PaymentTerm // extends CommonObject
$result = $object->create($user);
// Other options
if ($result < 0)
{
if ($result < 0) {
$this->error = $object->error;
$error++;
}
@ -382,8 +410,7 @@ class PaymentTerm // extends CommonObject
unset($object->context['createfromclone']);
// End
if (!$error)
{
if (!$error) {
$this->db->commit();
return $object->id;
} else {

View File

@ -45,7 +45,9 @@ $socid = GETPOST('socid', 'int');
$action = GETPOST('action', 'aZ09');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'facture', $id);
$object = new Facture($db);
@ -55,47 +57,39 @@ $object = new Facture($db);
* Add a new contact
*/
if ($action == 'addcontact' && $user->rights->facture->creer)
{
if ($action == 'addcontact' && $user->rights->facture->creer) {
$result = $object->fetch($id);
if ($result > 0 && $id > 0)
{
if ($result > 0 && $id > 0) {
$contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
}
if ($result >= 0)
{
if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
} else {
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$langs->load("errors");
setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
} // Toggle the status of a contact
elseif ($action == 'swapstatut' && $user->rights->facture->creer)
{
if ($object->fetch($id))
{
} elseif ($action == 'swapstatut' && $user->rights->facture->creer) {
// Toggle the status of a contact
if ($object->fetch($id)) {
$result = $object->swapContactStatus(GETPOST('ligne'));
} else {
dol_print_error($db);
}
} // Deletes a contact
elseif ($action == 'deletecontact' && $user->rights->facture->creer)
{
} elseif ($action == 'deletecontact' && $user->rights->facture->creer) {
// Deletes a contact
$object->fetch($id);
$result = $object->delete_contact($lineid);
if ($result >= 0)
{
if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
} else {
@ -124,10 +118,8 @@ $userstatic = new User($db);
/* */
/* *************************************************************************** */
if ($id > 0 || !empty($ref))
{
if ($object->fetch($id, $ref) > 0)
{
if ($id > 0 || !empty($ref)) {
if ($object->fetch($id, $ref) > 0) {
$object->fetch_thirdparty();
$head = facture_prepare_head($object);
@ -147,12 +139,10 @@ if ($id > 0 || !empty($ref))
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->facture->creer)
{
if ($user->rights->facture->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';
@ -192,10 +182,11 @@ if ($id > 0 || !empty($ref))
// Contacts lines (modules that overwrite templates must declare this into descriptor)
$dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
foreach ($dirtpls as $reldir)
{
foreach ($dirtpls as $reldir) {
$res = @include dol_buildpath($reldir.'/contacts.tpl.php');
if ($res) break;
if ($res) {
break;
}
}
} else {
// Record not found

View File

@ -49,8 +49,7 @@ $action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
// Security check
if ($user->socid)
{
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'facture', $id, '');
@ -60,16 +59,21 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) $sortfield = "name";
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "name";
}
$object = new Facture($db);
if ($object->fetch($id))
{
if ($object->fetch($id)) {
$object->fetch_thirdparty();
$upload_dir = $conf->facture->dir_output."/".dol_sanitizeFileName($object->ref);
}
@ -92,10 +96,8 @@ llxHeader('', $title, $helpurl);
$form = new Form($db);
if ($id > 0 || !empty($ref))
{
if ($object->fetch($id, $ref) > 0)
{
if ($id > 0 || !empty($ref)) {
if ($object->fetch($id, $ref) > 0) {
$object->fetch_thirdparty();
$upload_dir = $conf->facture->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
@ -108,8 +110,7 @@ if ($id > 0 || !empty($ref))
// Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0;
foreach ($filearray as $key => $file)
{
foreach ($filearray as $key => $file) {
$totalsize += $file['size'];
}
@ -125,15 +126,14 @@ if ($id > 0 || !empty($ref))
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->facture->creer)
{
if ($action != 'classify')
if ($user->rights->facture->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';
}
if ($action == 'classify') {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

View File

@ -34,8 +34,7 @@ $langs->load('bills');
// Filter to show only result of one customer
$socid = GETPOST('socid', 'int');
if (isset($user->socid) && $user->socid > 0)
{
if (isset($user->socid) && $user->socid > 0) {
$action = '';
$socid = $user->socid;
}
@ -58,8 +57,7 @@ print '<div class="fichecenter">';
print '<div class="fichethirdleft">';
// This is useless due to the global search combo
if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))
{
if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) {
print getAreaSearchFrom();
print '<br>';
}
@ -129,16 +127,21 @@ function getPieChart($socid = 0)
$sql = "SELECT count(f.rowid), f.fk_statut";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ", ".MAIN_DB_PREFIX."facture as f";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND f.entity IN (".getEntity('facture').")";
if ($user->socid) $sql .= ' AND f.fk_soc = '.$user->socid;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($user->socid) {
$sql .= ' AND f.fk_soc = '.$user->socid;
}
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$sql .= " GROUP BY f.fk_statut";
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
return '';
}
@ -149,11 +152,9 @@ function getPieChart($socid = 0)
$total = 0;
$vals = [];
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
if ($row)
{
if ($row) {
$vals[$row[1]] = $row[0];
$total += $row[0];
}
@ -173,14 +174,12 @@ function getPieChart($socid = 0)
$array = [Facture::STATUS_DRAFT, Facture::STATUS_VALIDATED, Facture::STATUS_CLOSED, Facture::STATUS_ABANDONED];
$dataseries = [];
foreach ($array as $status)
{
foreach ($array as $status) {
$objectstatic->statut = $status;
$objectstatic->paye = $status == Facture::STATUS_CLOSED ? -1 : 0;
$dataseries[] = [$objectstatic->getLibStatut(1), (isset($vals[$status]) ? (int) $vals[$status] : 0)];
if (!$conf->use_javascript_ajax)
{
if (!$conf->use_javascript_ajax) {
$result .= '<tr class="oddeven">';
$result .= '<td>'.$objectstatic->getLibStatut(0).'</td>';
$result .= '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
@ -188,8 +187,7 @@ function getPieChart($socid = 0)
}
}
if ($conf->use_javascript_ajax)
{
if ($conf->use_javascript_ajax) {
$dolgraph = new DolGraph();
$dolgraph->SetData($dataseries);
$dolgraph->setShowLegend(2);
@ -227,17 +225,22 @@ function getDraftTable($maxCount = 500, $socid = 0)
$sql = "SELECT f.rowid, f.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client, f.total as total_ttc";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND f.entity IN (".getEntity('facture').")";
$sql .= " AND f.fk_statut = ".Facture::STATUS_DRAFT;
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$sql .= $db->plimit($maxCount, 0);
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
return '';
}
@ -256,8 +259,7 @@ function getDraftTable($maxCount = 500, $socid = 0)
$result .= '</td>';
$result .= '</tr>';
if ($num < 1)
{
if ($num < 1) {
$result .= '</table>';
$result .= '</div>';
return $result;
@ -269,8 +271,7 @@ function getDraftTable($maxCount = 500, $socid = 0)
$total = 0;
$i = 0;
while ($i < $nbofloop)
{
while ($i < $nbofloop) {
$obj = $db->fetch_object($resql);
$objectstatic->id = $obj->rowid;
@ -291,14 +292,11 @@ function getDraftTable($maxCount = 500, $socid = 0)
$total += $obj->total_ttc;
}
if ($num > $nbofloop)
{
if ($num > $nbofloop) {
$result .= '<tr class="liste_total">';
$result .= '<td colspan="3" class="right">'.$langs->trans("XMoreLines", ($num - $nbofloop)).'</td>';
$result .= '</tr>';
}
elseif ($total > 0)
{
} elseif ($total > 0) {
$result .= '<tr class="liste_total">';
$result .= '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
$result .= '<td class="right">'.price($total).'</td>';
@ -325,17 +323,22 @@ function getLatestEditTable($maxCount = 5, $socid = 0)
$sql .= " f.datec";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND f.entity IN (".getEntity('facture').")";
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
$sql .= " ORDER BY f.tms DESC";
$sql .= $db->plimit($maxCount, 0);
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
}
@ -348,8 +351,7 @@ function getLatestEditTable($maxCount = 5, $socid = 0)
$result .= '<td colspan="4">'.$langs->trans("LastCustomersBills", $maxCount).'</td>';
$result .= '</tr>';
if ($num < 1)
{
if ($num < 1) {
$result .= '</table>';
$result .= '</div>';
return $result;
@ -360,8 +362,7 @@ function getLatestEditTable($maxCount = 5, $socid = 0)
$companystatic = new Societe($db);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
$objectstatic->id = $obj->rowid;
@ -421,18 +422,23 @@ function getOpenTable($maxCount = 500, $socid = 0)
$sql .= ", f.datef as df, f.date_lim_reglement as datelimite";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql .= ", ".MAIN_DB_PREFIX."facture as f";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE f.fk_soc = s.rowid";
$sql .= " AND f.entity IN (".getEntity('facture').")";
$sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND s.rowid = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND s.rowid = ".$socid;
}
$sql .= " ORDER BY f.rowid DESC";
$sql .= $db->plimit($maxCount, 0);
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
}
@ -450,8 +456,7 @@ function getOpenTable($maxCount = 500, $socid = 0)
$result .= '</td>';
$result .= '</tr>';
if ($num < 1)
{
if ($num < 1) {
$result .= '</table>';
$result .= '</div>';
return $result;
@ -465,8 +470,7 @@ function getOpenTable($maxCount = 500, $socid = 0)
$total = 0;
$i = 0;
while ($i < $nbofloop)
{
while ($i < $nbofloop) {
$obj = $db->fetch_object($resql);
$objectstatic->id = $obj->id;
@ -490,8 +494,7 @@ function getOpenTable($maxCount = 500, $socid = 0)
$result .= '<td width="18" class="nobordernopadding nowrap">';
if ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay))
{
if ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) {
$result .= img_warning($langs->trans("Late"));
}
@ -513,14 +516,11 @@ function getOpenTable($maxCount = 500, $socid = 0)
$total += $obj->total_ttc;
}
if ($num > $nbofloop)
{
if ($num > $nbofloop) {
$result .= '<tr class="liste_total">';
$result .= '<td colspan="4" class="right">'.$langs->trans("XMoreLines", ($num - $nbofloop)).'</td>';
$result .= '</tr>';
}
elseif ($total > 0)
{
} elseif ($total > 0) {
$result .= '<tr class="liste_total">';
$result .= '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
$result .= '<td align="right">'.price($total).'</td>';

View File

@ -71,15 +71,14 @@ $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_cl
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->facture->creer)
{
if ($action != 'classify')
if ($user->rights->facture->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';
}
if ($action == 'classify') {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

View File

@ -59,9 +59,13 @@ $socid = GETPOST('socid', 'int');
$id = (GETPOST('facid', 'int') ?GETPOST('facid', 'int') : GETPOST('id', 'int'));
$lineid = GETPOST('lineid', 'int');
$ref = GETPOST('ref', 'alpha');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$objecttype = 'facture_rec';
if ($action == "create" || $action == "add") $objecttype = '';
if ($action == "create" || $action == "add") {
$objecttype = '';
}
$result = restrictedArea($user, 'facture', $id, $objecttype);
$search_ref = GETPOST('search_ref');
@ -86,19 +90,23 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
if (!$sortorder) $sortorder = 'DESC';
if (!$sortfield) $sortfield = 'f.titre';
if (!$sortorder) {
$sortorder = 'DESC';
}
if (!$sortfield) {
$sortfield = 'f.titre';
}
$pageprev = $page - 1;
$pagenext = $page + 1;
$object = new FactureRec($db);
if (($id > 0 || $ref) && $action != 'create' && $action != 'add')
{
if (($id > 0 || $ref) && $action != 'create' && $action != 'add') {
$ret = $object->fetch($id, $ref);
if (!$ret)
{
if (!$ret) {
setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
}
}
@ -143,37 +151,47 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
if ($socid > 0) {
$tmpthirdparty = new Societe($db);
$res = $tmpthirdparty->fetch($socid);
if ($res > 0) $search_societe = $tmpthirdparty->name;
if ($res > 0) {
$search_societe = $tmpthirdparty->name;
}
}
if ($socid > 0) {
$tmpthirdparty = new Societe($db);
$res = $tmpthirdparty->fetch($socid);
if ($res > 0) $search_societe = $tmpthirdparty->name;
if ($res > 0) {
$search_societe = $tmpthirdparty->name;
}
}
/*
* Actions
*/
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
if (GETPOST('cancel', 'alpha')) {
$action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook))
{
if (GETPOST('cancel', 'alpha')) $action = '';
if (empty($reshook)) {
if (GETPOST('cancel', 'alpha')) {
$action = '';
}
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Do we click on purge search criteria ?
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
$search_ref = '';
$search_societe = '';
$search_montant_ht = '';
@ -196,11 +214,11 @@ if (empty($reshook))
// Mass actions
/*$objectclass='MyObject';
$objectlabel='MyObject';
$permissiontoread = $user->rights->mymodule->read;
$permissiontodelete = $user->rights->mymodule->delete;
$uploaddir = $conf->mymodule->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';*/
$objectlabel='MyObject';
$permissiontoread = $user->rights->mymodule->read;
$permissiontodelete = $user->rights->mymodule->delete;
$uploaddir = $conf->mymodule->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';*/
}
@ -212,7 +230,9 @@ llxHeader('', $langs->trans("RepeatableInvoices"), 'ch-facture.html#s-fac-factur
$form = new Form($db);
$formother = new FormOther($db);
if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }
if (!empty($conf->projet->enabled)) {
$formproject = new FormProjets($db);
}
$companystatic = new Societe($db);
$invoicerectmp = new FactureRec($db);
@ -231,7 +251,9 @@ $sql .= " f.datec, f.tms,";
$sql .= " f.fk_cond_reglement, f.fk_mode_reglement";
// Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
}
}
// Add fields from hooks
$parameters = array();
@ -249,23 +271,52 @@ $sql .= ' AND f.entity IN ('.getEntity('invoice').')';
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($search_ref) $sql .= natural_search('f.titre', $search_ref);
if ($socid) $sql .= ' AND s.rowid = '.(int) $socid;
if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
if ($search_montant_ht != '') $sql .= natural_search('f.total', $search_montant_ht, 1);
if ($search_montant_vat != '') $sql .= natural_search('f.tva', $search_montant_vat, 1);
if ($search_montant_ttc != '') $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
if (!empty($search_payment_mode) && $search_payment_mode != '-1') $sql .= natural_search('f.fk_mode_reglement', $search_payment_mode, 1);
if (!empty($search_payment_term) && $search_payment_term != '-1') $sql .= natural_search('f.fk_cond_reglement', $search_payment_term, 1);
if ($search_recurring == '1') $sql .= ' AND f.frequency > 0';
if ($search_recurring == '0') $sql .= ' AND (f.frequency IS NULL or f.frequency = 0)';
if ($search_frequency != '') $sql .= natural_search('f.frequency', $search_frequency, 1);
if ($search_unit_frequency != '') $sql .= ' AND f.frequency > 0'.natural_search('f.unit_frequency', $search_unit_frequency);
if ($search_status != '' && $search_status >= -1)
{
if ($search_status == 0) $sql .= ' AND frequency = 0 AND suspended = 0';
if ($search_status == 1) $sql .= ' AND frequency != 0 AND suspended = 0';
if ($search_status == -1) $sql .= ' AND suspended = 1';
if ($search_ref) {
$sql .= natural_search('f.titre', $search_ref);
}
if ($socid) {
$sql .= ' AND s.rowid = '.(int) $socid;
}
if ($search_societe) {
$sql .= natural_search('s.nom', $search_societe);
}
if ($search_montant_ht != '') {
$sql .= natural_search('f.total', $search_montant_ht, 1);
}
if ($search_montant_vat != '') {
$sql .= natural_search('f.tva', $search_montant_vat, 1);
}
if ($search_montant_ttc != '') {
$sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
}
if (!empty($search_payment_mode) && $search_payment_mode != '-1') {
$sql .= natural_search('f.fk_mode_reglement', $search_payment_mode, 1);
}
if (!empty($search_payment_term) && $search_payment_term != '-1') {
$sql .= natural_search('f.fk_cond_reglement', $search_payment_term, 1);
}
if ($search_recurring == '1') {
$sql .= ' AND f.frequency > 0';
}
if ($search_recurring == '0') {
$sql .= ' AND (f.frequency IS NULL or f.frequency = 0)';
}
if ($search_frequency != '') {
$sql .= natural_search('f.frequency', $search_frequency, 1);
}
if ($search_unit_frequency != '') {
$sql .= ' AND f.frequency > 0'.natural_search('f.unit_frequency', $search_unit_frequency);
}
if ($search_status != '' && $search_status >= -1) {
if ($search_status == 0) {
$sql .= ' AND frequency = 0 AND suspended = 0';
}
if ($search_status == 1) {
$sql .= ' AND frequency != 0 AND suspended = 0';
}
if ($search_status == -1) {
$sql .= ' AND suspended = 1';
}
}
$sql .= dolSqlDateFilter('f.date_last_gen', $search_day, $search_month, $search_year);
$sql .= dolSqlDateFilter('f.date_when', $search_day_date_when, $search_month_date_when, $search_year_date_when);
@ -273,12 +324,10 @@ $sql .= dolSqlDateFilter('f.date_when', $search_day_date_when, $search_month_dat
$sql .= $db->order($sortfield, $sortorder);
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@ -287,32 +336,73 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if ($socid > 0) $param .= '&socid='.urlencode($socid);
if ($search_day) $param .= '&search_day='.urlencode($search_day);
if ($search_month) $param .= '&search_month='.urlencode($search_month);
if ($search_year) $param .= '&search_year='.urlencode($search_year);
if ($search_day_date_when) $param .= '&search_day_date_when='.urlencode($search_day_date_when);
if ($search_month_date_when) $param .= '&search_month_date_when='.urlencode($search_month_date_when);
if ($search_year_date_when) $param .= '&search_year_date_when='.urlencode($search_year_date_when);
if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
if ($search_societe) $param .= '&search_societe='.urlencode($search_societe);
if ($search_montant_ht != '') $param .= '&search_montant_ht='.urlencode($search_montant_ht);
if ($search_montant_vat != '') $param .= '&search_montant_vat='.urlencode($search_montant_vat);
if ($search_montant_ttc != '') $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
if ($search_payment_mode != '') $param .= '&search_payment_mode='.urlencode($search_payment_mode);
if ($search_payment_term != '') $param .= '&search_payment_term='.urlencode($search_payment_term);
if ($search_recurring != '' && $search_recurrning != '-1') $param .= '&search_recurring='.urlencode($search_recurring);
if ($search_frequency > 0) $param .= '&search_frequency='.urlencode($search_frequency);
if ($search_unit_frequency != '') $param .= '&search_unit_frequency='.urlencode($search_unit_frequency);
if ($search_status != '') $param .= '&search_status='.urlencode($search_status);
if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($socid > 0) {
$param .= '&socid='.urlencode($socid);
}
if ($search_day) {
$param .= '&search_day='.urlencode($search_day);
}
if ($search_month) {
$param .= '&search_month='.urlencode($search_month);
}
if ($search_year) {
$param .= '&search_year='.urlencode($search_year);
}
if ($search_day_date_when) {
$param .= '&search_day_date_when='.urlencode($search_day_date_when);
}
if ($search_month_date_when) {
$param .= '&search_month_date_when='.urlencode($search_month_date_when);
}
if ($search_year_date_when) {
$param .= '&search_year_date_when='.urlencode($search_year_date_when);
}
if ($search_ref) {
$param .= '&search_ref='.urlencode($search_ref);
}
if ($search_societe) {
$param .= '&search_societe='.urlencode($search_societe);
}
if ($search_montant_ht != '') {
$param .= '&search_montant_ht='.urlencode($search_montant_ht);
}
if ($search_montant_vat != '') {
$param .= '&search_montant_vat='.urlencode($search_montant_vat);
}
if ($search_montant_ttc != '') {
$param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
}
if ($search_payment_mode != '') {
$param .= '&search_payment_mode='.urlencode($search_payment_mode);
}
if ($search_payment_term != '') {
$param .= '&search_payment_term='.urlencode($search_payment_term);
}
if ($search_recurring != '' && $search_recurrning != '-1') {
$param .= '&search_recurring='.urlencode($search_recurring);
}
if ($search_frequency > 0) {
$param .= '&search_frequency='.urlencode($search_frequency);
}
if ($search_unit_frequency != '') {
$param .= '&search_unit_frequency='.urlencode($search_unit_frequency);
}
if ($search_status != '') {
$param .= '&search_status='.urlencode($search_status);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
@ -323,7 +413,9 @@ if ($resql)
//$selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
@ -348,93 +440,84 @@ if ($resql)
// Filters lines
print '<tr class="liste_titre_filter">';
// Ref
if (!empty($arrayfields['f.titre']['checked']))
{
if (!empty($arrayfields['f.titre']['checked'])) {
print '<td class="liste_titre left">';
print '<input class="flat maxwidth100" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
print '</td>';
}
// Thirpdarty
if (!empty($arrayfields['s.nom']['checked']))
{
if (!empty($arrayfields['s.nom']['checked'])) {
print '<td class="liste_titre left"><input class="flat" type="text" size="8" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
}
if (!empty($arrayfields['f.total']['checked']))
{
if (!empty($arrayfields['f.total']['checked'])) {
// Amount net
print '<td class="liste_titre right">';
print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
print '</td>';
}
if (!empty($arrayfields['f.tva']['checked']))
{
if (!empty($arrayfields['f.tva']['checked'])) {
// Amount Vat
print '<td class="liste_titre right">';
print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
print '</td>';
}
if (!empty($arrayfields['f.total_ttc']['checked']))
{
if (!empty($arrayfields['f.total_ttc']['checked'])) {
// Amount
print '<td class="liste_titre right">';
print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
print '</td>';
}
if (!empty($arrayfields['f.fk_cond_reglement']['checked']))
{
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
// Payment term
print '<td class="liste_titre right">';
$form->select_conditions_paiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100');
print "</td>";
}
if (!empty($arrayfields['f.fk_mode_reglement']['checked']))
{
if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
// Payment mode
print '<td class="liste_titre right">';
$form->select_types_paiements($search_payment_mode, 'search_payment_mode', '', 0, 1, 1, 0, 1, 'maxwidth100');
print '</td>';
}
if (!empty($arrayfields['recurring']['checked']))
{
if (!empty($arrayfields['recurring']['checked'])) {
// Recurring or not
print '<td class="liste_titre" align="center">';
print $form->selectyesno('search_recurring', $search_recurring, 1, false, 1);
print '</td>';
}
if (!empty($arrayfields['f.frequency']['checked']))
{
if (!empty($arrayfields['f.frequency']['checked'])) {
// Recurring or not
print '<td class="liste_titre" align="center">';
print '<input class="flat" type="text" size="1" name="search_frequency" value="'.dol_escape_htmltag($search_frequency).'">';
print '</td>';
}
if (!empty($arrayfields['f.unit_frequency']['checked']))
{
if (!empty($arrayfields['f.unit_frequency']['checked'])) {
// Frequency unit
print '<td class="liste_titre" align="center">';
print '<input class="flat" type="text" size="1" name="search_unit_frequency" value="'.dol_escape_htmltag($search_unit_frequency).'">';
print '</td>';
}
if (!empty($arrayfields['f.nb_gen_done']['checked']))
{
if (!empty($arrayfields['f.nb_gen_done']['checked'])) {
// Nb generation
print '<td class="liste_titre" align="center">';
print '</td>';
}
// Date invoice
if (!empty($arrayfields['f.date_last_gen']['checked']))
{
if (!empty($arrayfields['f.date_last_gen']['checked'])) {
print '<td class="liste_titre nowraponall" align="center">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
}
print '<input class="flat valignmiddle width25" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
$formother->select_year($search_year ? $search_year : -1, 'search_year', 1, 20, 5, 0, 0, '', 'widthauto valignmiddle');
print '</td>';
}
// Date next generation
if (!empty($arrayfields['f.date_when']['checked']))
{
if (!empty($arrayfields['f.date_when']['checked'])) {
print '<td class="liste_titre nowraponall" align="center">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day_date_when" value="'.$search_day_date_when.'">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day_date_when" value="'.$search_day_date_when.'">';
}
print '<input class="flat valignmiddle width25" type="text" size="1" maxlength="2" name="search_month_date_when" value="'.$search_month_date_when.'">';
$formother->select_year($search_year_date_when ? $search_year_date_when : -1, 'search_year_date_when', 1, 20, 5, 0, 0, '', 'widthauto valignmiddle');
print '</td>';
@ -447,20 +530,17 @@ if ($resql)
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// Date creation
if (!empty($arrayfields['f.datec']['checked']))
{
if (!empty($arrayfields['f.datec']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Date modification
if (!empty($arrayfields['f.tms']['checked']))
{
if (!empty($arrayfields['f.tms']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Status
if (!empty($arrayfields['status']['checked']))
{
if (!empty($arrayfields['status']['checked'])) {
print '<td class="liste_titre" align="center">';
$liststatus = array(
0=>$langs->trans("Draft"),
@ -478,35 +558,67 @@ if ($resql)
print "</tr>\n";
print '<tr class="liste_titre">';
if (!empty($arrayfields['f.titre']['checked'])) print_liste_field_titre($arrayfields['f.titre']['label'], $_SERVER['PHP_SELF'], "f.titre", "", $param, "", $sortfield, $sortorder);
if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], "s.nom", "", $param, "", $sortfield, $sortorder);
if (!empty($arrayfields['f.total']['checked'])) print_liste_field_titre($arrayfields['f.total']['label'], $_SERVER['PHP_SELF'], "f.total", "", $param, 'class="right"', $sortfield, $sortorder);
if (!empty($arrayfields['f.tva']['checked'])) print_liste_field_titre($arrayfields['f.tva']['label'], $_SERVER['PHP_SELF'], "f.tva", "", $param, 'class="right"', $sortfield, $sortorder);
if (!empty($arrayfields['f.total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder);
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER['PHP_SELF'], "f.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER['PHP_SELF'], "f.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['recurring']['checked'])) print_liste_field_titre($arrayfields['recurring']['label'], $_SERVER['PHP_SELF'], "recurring", "", $param, 'class="center"', $sortfield, $sortorder);
if (!empty($arrayfields['f.frequency']['checked'])) print_liste_field_titre($arrayfields['f.frequency']['label'], $_SERVER['PHP_SELF'], "f.frequency", "", $param, 'align="center"', $sortfield, $sortorder);
if (!empty($arrayfields['f.unit_frequency']['checked'])) print_liste_field_titre($arrayfields['f.unit_frequency']['label'], $_SERVER['PHP_SELF'], "f.unit_frequency", "", $param, 'align="center"', $sortfield, $sortorder);
if (!empty($arrayfields['f.nb_gen_done']['checked'])) print_liste_field_titre($arrayfields['f.nb_gen_done']['label'], $_SERVER['PHP_SELF'], "f.nb_gen_done", "", $param, 'align="center"', $sortfield, $sortorder);
if (!empty($arrayfields['f.date_last_gen']['checked'])) print_liste_field_titre($arrayfields['f.date_last_gen']['label'], $_SERVER['PHP_SELF'], "f.date_last_gen", "", $param, 'align="center"', $sortfield, $sortorder);
if (!empty($arrayfields['f.date_when']['checked'])) print_liste_field_titre($arrayfields['f.date_when']['label'], $_SERVER['PHP_SELF'], "f.date_when", "", $param, 'align="center"', $sortfield, $sortorder);
if (!empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER['PHP_SELF'], "f.datec", "", $param, 'align="center"', $sortfield, $sortorder);
if (!empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER['PHP_SELF'], "f.tms", "", $param, 'align="center"', $sortfield, $sortorder);
if (!empty($arrayfields['f.titre']['checked'])) {
print_liste_field_titre($arrayfields['f.titre']['label'], $_SERVER['PHP_SELF'], "f.titre", "", $param, "", $sortfield, $sortorder);
}
if (!empty($arrayfields['s.nom']['checked'])) {
print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], "s.nom", "", $param, "", $sortfield, $sortorder);
}
if (!empty($arrayfields['f.total']['checked'])) {
print_liste_field_titre($arrayfields['f.total']['label'], $_SERVER['PHP_SELF'], "f.total", "", $param, 'class="right"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.tva']['checked'])) {
print_liste_field_titre($arrayfields['f.tva']['label'], $_SERVER['PHP_SELF'], "f.tva", "", $param, 'class="right"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.total_ttc']['checked'])) {
print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER['PHP_SELF'], "f.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER['PHP_SELF'], "f.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['recurring']['checked'])) {
print_liste_field_titre($arrayfields['recurring']['label'], $_SERVER['PHP_SELF'], "recurring", "", $param, 'class="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.frequency']['checked'])) {
print_liste_field_titre($arrayfields['f.frequency']['label'], $_SERVER['PHP_SELF'], "f.frequency", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.unit_frequency']['checked'])) {
print_liste_field_titre($arrayfields['f.unit_frequency']['label'], $_SERVER['PHP_SELF'], "f.unit_frequency", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.nb_gen_done']['checked'])) {
print_liste_field_titre($arrayfields['f.nb_gen_done']['label'], $_SERVER['PHP_SELF'], "f.nb_gen_done", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.date_last_gen']['checked'])) {
print_liste_field_titre($arrayfields['f.date_last_gen']['label'], $_SERVER['PHP_SELF'], "f.date_last_gen", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.date_when']['checked'])) {
print_liste_field_titre($arrayfields['f.date_when']['label'], $_SERVER['PHP_SELF'], "f.date_when", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.datec']['checked'])) {
print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER['PHP_SELF'], "f.datec", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['f.tms']['checked'])) {
print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER['PHP_SELF'], "f.tms", "", $param, 'align="center"', $sortfield, $sortorder);
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
if (!empty($arrayfields['status']['checked'])) print_liste_field_titre($arrayfields['status']['label'], $_SERVER['PHP_SELF'], "f.suspended,f.frequency", "", $param, 'align="center"', $sortfield, $sortorder);
if (!empty($arrayfields['status']['checked'])) {
print_liste_field_titre($arrayfields['status']['label'], $_SERVER['PHP_SELF'], "f.suspended,f.frequency", "", $param, 'align="center"', $sortfield, $sortorder);
}
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'center maxwidthsearch ');
print "</tr>\n";
if ($num > 0)
{
if ($num > 0) {
$i = 0;
$totalarray = array();
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($resql);
if (empty($objp)) break;
if (empty($objp)) {
break;
}
$companystatic->id = $objp->socid;
$companystatic->name = $objp->name;
@ -521,115 +633,137 @@ if ($resql)
print '<tr class="oddeven">';
if (!empty($arrayfields['f.titre']['checked']))
{
if (!empty($arrayfields['f.titre']['checked'])) {
print '<td class="nowrap tdoverflowmax200">';
print $invoicerectmp->getNomUrl(1);
print "</a>";
print "</td>\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['s.nom']['checked']))
{
if (!empty($arrayfields['s.nom']['checked'])) {
print '<td class="tdoverflowmax200">'.$companystatic->getNomUrl(1, 'customer').'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.total']['checked']))
{
if (!empty($arrayfields['f.total']['checked'])) {
print '<td class="nowrap right">'.price($objp->total).'</td>'."\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'f.total';
}
$totalarray['val']['f.total'] += $objp->total;
}
if (!empty($arrayfields['f.tva']['checked']))
{
if (!empty($arrayfields['f.tva']['checked'])) {
print '<td class="nowrap right">'.price($objp->total_vat).'</td>'."\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.tva';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'f.tva';
}
$totalarray['val']['f.tva'] += $objp->total_vat;
}
if (!empty($arrayfields['f.total_ttc']['checked']))
{
if (!empty($arrayfields['f.total_ttc']['checked'])) {
print '<td class="nowrap right">'.price($objp->total_ttc).'</td>'."\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
}
$totalarray['val']['f.total_ttc'] += $objp->total_ttc;
}
// Payment term
if (!empty($arrayfields['f.fk_cond_reglement']['checked']))
{
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
print '<td class="right">';
$form->form_conditions_reglement('', $objp->fk_cond_reglement, 'none');
print '</td>'."\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Payment mode
if (!empty($arrayfields['f.fk_mode_reglement']['checked']))
{
if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
print '<td class="right">';
$form->form_modes_reglement('', $objp->fk_mode_reglement, 'none');
print '</td>'."\n";
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['recurring']['checked']))
{
if (!empty($arrayfields['recurring']['checked'])) {
print '<td class="center">'.yn($objp->frequency ? 1 : 0).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.frequency']['checked']))
{
if (!empty($arrayfields['f.frequency']['checked'])) {
print '<td class="center">'.($objp->frequency > 0 ? $objp->frequency : '').'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.unit_frequency']['checked']))
{
if (!empty($arrayfields['f.unit_frequency']['checked'])) {
print '<td class="center">'.($objp->frequency > 0 ? $objp->unit_frequency : '').'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.nb_gen_done']['checked']))
{
if (!empty($arrayfields['f.nb_gen_done']['checked'])) {
print '<td class="center">';
print ($objp->frequency > 0 ? $objp->nb_gen_done.($objp->nb_gen_max > 0 ? ' / '.$objp->nb_gen_max : '') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date last generation
if (!empty($arrayfields['f.date_last_gen']['checked']))
{
if (!empty($arrayfields['f.date_last_gen']['checked'])) {
print '<td class="center">';
print ($objp->frequency > 0 ? dol_print_date($db->jdate($objp->date_last_gen), 'day') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date next generation
if (!empty($arrayfields['f.date_when']['checked']))
{
if (!empty($arrayfields['f.date_when']['checked'])) {
print '<td class="center">';
print '<div class="nowraponall">';
print ($objp->frequency ? ($invoicerectmp->isMaxNbGenReached() ? '<strike>' : '').dol_print_date($db->jdate($objp->date_when), 'day').($invoicerectmp->isMaxNbGenReached() ? '</strike>' : '') : '<span class="opacitymedium">'.$langs->trans('NA').'</span>');
if (!$invoicerectmp->isMaxNbGenReached())
{
if (!$objp->suspended && $objp->frequency > 0 && $db->jdate($objp->date_when) && $db->jdate($objp->date_when) < $now) print img_warning($langs->trans("Late"));
if (!$invoicerectmp->isMaxNbGenReached()) {
if (!$objp->suspended && $objp->frequency > 0 && $db->jdate($objp->date_when) && $db->jdate($objp->date_when) < $now) {
print img_warning($langs->trans("Late"));
}
} else {
print img_info($langs->trans("MaxNumberOfGenerationReached"));
}
print '</div>';
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.datec']['checked']))
{
if (!empty($arrayfields['f.datec']['checked'])) {
print '<td class="center">';
print dol_print_date($db->jdate($objp->datec), 'dayhour');
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
if (!empty($arrayfields['f.tms']['checked']))
{
if (!empty($arrayfields['f.tms']['checked'])) {
print '<td class="center">';
print dol_print_date($db->jdate($objp->tms), 'dayhour');
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
$obj = $objp;
@ -644,17 +778,16 @@ if ($resql)
print '<td class="center">';
print $invoicerectmp->getLibStatut(3, 0);
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Action column
print '<td class="center">';
if ($user->rights->facture->creer && empty($invoicerectmp->suspended))
{
if ($invoicerectmp->isMaxNbGenReached())
{
if ($user->rights->facture->creer && empty($invoicerectmp->suspended)) {
if ($invoicerectmp->isMaxNbGenReached()) {
print $langs->trans("MaxNumberOfGenerationReached");
} elseif (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today)
{
} elseif (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today) {
print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;socid='.$objp->socid.'&amp;fac_rec='.$objp->facid.'">';
print $langs->trans("CreateBill").'</a>';
} else {
@ -663,7 +796,9 @@ if ($resql)
} else {
print "&nbsp;";
}
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
print "</td>";
print "</tr>\n";
@ -672,7 +807,11 @@ if ($resql)
}
} else {
$colspan = 1;
foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
foreach ($arrayfields as $key => $val) {
if (!empty($val['checked'])) {
$colspan++;
}
}
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
}

File diff suppressed because it is too large Load Diff

View File

@ -43,7 +43,9 @@ $action = GETPOST('action', 'aZ09');
// Security check
$socid = 0;
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'facture', $id, '');
$object = new Facture($db);
@ -70,8 +72,7 @@ llxHeader('', $title, $helpurl);
$form = new Form($db);
if ($id > 0 || !empty($ref))
{
if ($id > 0 || !empty($ref)) {
$object = new Facture($db);
$object->fetch($id, $ref);
@ -94,15 +95,14 @@ if ($id > 0 || !empty($ref))
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer');
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->facture->creer)
{
if ($action != 'classify')
if ($user->rights->facture->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';
}
if ($action == 'classify') {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

View File

@ -48,7 +48,9 @@ $action = GETPOST('action', 'aZ09');
$type = GETPOST('type', 'aZ09');
$fieldid = (!empty($ref) ? 'ref' : 'rowid');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
if ($type == 'bank-transfer') {
$object = new FactureFournisseur($db);
@ -57,12 +59,10 @@ if ($type == 'bank-transfer') {
}
// Load object
if ($id > 0 || !empty($ref))
{
if ($id > 0 || !empty($ref)) {
$ret = $object->fetch($id, $ref);
$isdraft = (($object->statut == FactureFournisseur::STATUS_DRAFT) ? 1 : 0);
if ($ret > 0)
{
if ($ret > 0) {
$object->fetch_thirdparty();
}
}
@ -71,10 +71,14 @@ $hookmanager->initHooks(array('directdebitcard', 'globalcard'));
if ($type == 'bank-transfer') {
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture', 'fk_soc', $fieldid, $isdraft);
if (!$user->rights->fournisseur->facture->lire) accessforbidden();
if (!$user->rights->fournisseur->facture->lire) {
accessforbidden();
}
} else {
$result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid, $isdraft);
if (!$user->rights->facture->lire) accessforbidden();
if (!$user->rights->facture->lire) {
accessforbidden();
}
}
@ -84,14 +88,13 @@ if ($type == 'bank-transfer') {
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook))
{
if ($action == "new")
{
if ($object->id > 0)
{
if (empty($reshook)) {
if ($action == "new") {
if ($object->id > 0) {
$db->begin();
$newtype = $type;
@ -102,8 +105,7 @@ if (empty($reshook))
}
$result = $object->demande_prelevement($user, price2num(GETPOST('withdraw_request_amount', 'alpha')), $newtype, $sourcetype);
if ($result > 0)
{
if ($result > 0) {
$db->commit();
setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
@ -115,13 +117,10 @@ if (empty($reshook))
$action = '';
}
if ($action == "delete")
{
if ($object->id > 0)
{
if ($action == "delete") {
if ($object->id > 0) {
$result = $object->demande_prelevement_delete($user, GETPOST('did', 'int'));
if ($result == 0)
{
if ($result == 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id.'&type='.$type);
exit;
}
@ -155,8 +154,7 @@ llxHeader('', $title, $helpurl);
/* */
/* *************************************************************************** */
if ($object->id > 0)
{
if ($object->id > 0) {
$selleruserevenustamp = $mysoc->useRevenueStamp();
$totalpaye = $object->getSommePaiement();
@ -170,7 +168,9 @@ if ($object->id > 0)
//$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
$resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
if ($object->paye) $resteapayer = 0;
if ($object->paye) {
$resteapayer = 0;
}
$resteapayeraffiche = $resteapayer;
if ($type == 'bank-transfer') {
@ -202,8 +202,7 @@ if ($object->id > 0)
}
$author = new User($db);
if ($object->user_author)
{
if ($object->user_author) {
$author->fetch($object->user_author);
}
@ -234,17 +233,19 @@ if ($object->id > 0)
// Thirdparty
$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
if ($type == 'bank-transfer') {
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
$morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
}
} else {
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
$morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->thirdparty->id.'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)';
}
}
// Project
if (!empty($conf->projet->enabled))
{
if (!empty($conf->projet->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
if ($user->rights->facture->creer)
{
if ($user->rights->facture->creer) {
if ($action != 'classify') {
//$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
$morehtmlref .= ' : ';
@ -293,8 +294,7 @@ if ($object->id > 0)
if ($object->module_source) {
print ' <span class="opacitymediumbycolor">('.$langs->trans("POS").' '.$object->module_source.' - '.$langs->trans("Terminal").' '.$object->pos_source.')</span>';
}
if ($object->type == $object::TYPE_REPLACEMENT)
{
if ($object->type == $object::TYPE_REPLACEMENT) {
if ($type == 'bank-transfer') {
$facreplaced = new FactureFournisseur($db);
} else {
@ -303,8 +303,7 @@ if ($object->id > 0)
$facreplaced->fetch($object->fk_facture_source);
print ' ('.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).')';
}
if ($object->type == $object::TYPE_CREDIT_NOTE)
{
if ($object->type == $object::TYPE_CREDIT_NOTE) {
if ($type == 'bank-transfer') {
$facusing = new FactureFournisseur($db);
} else {
@ -315,14 +314,15 @@ if ($object->id > 0)
}
$facidavoir = $object->getListIdAvoirFromInvoice();
if (count($facidavoir) > 0)
{
if (count($facidavoir) > 0) {
print ' ('.$langs->transnoentities("InvoiceHasAvoir");
$i = 0;
foreach ($facidavoir as $id)
{
if ($i == 0) print ' ';
else print ',';
foreach ($facidavoir as $id) {
if ($i == 0) {
print ' ';
} else {
print ',';
}
if ($type == 'bank-transfer') {
$facavoir = new FactureFournisseur($db);
} else {
@ -374,14 +374,14 @@ if ($object->id > 0)
print '<table class="nobordernopadding centpercent"><tr><td>';
print $langs->trans('DateInvoice');
print '</td>';
if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && !empty($object->brouillon) && $user->rights->facture->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editinvoicedate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && !empty($object->brouillon) && $user->rights->facture->creer) {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editinvoicedate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
if ($object->type != $object::TYPE_CREDIT_NOTE)
{
if ($action == 'editinvoicedate')
{
if ($object->type != $object::TYPE_CREDIT_NOTE) {
if ($action == 'editinvoicedate') {
$form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $object->date, 'invoicedate');
} else {
print dol_print_date($object->date, 'day');
@ -397,13 +397,13 @@ if ($object->id > 0)
print '<table class="nobordernopadding centpercent"><tr><td>';
print $langs->trans('PaymentConditionsShort');
print '</td>';
if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editconditions' && !empty($object->brouillon) && $user->rights->facture->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editconditions' && !empty($object->brouillon) && $user->rights->facture->creer) {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
if ($object->type != $object::TYPE_CREDIT_NOTE)
{
if ($action == 'editconditions')
{
if ($object->type != $object::TYPE_CREDIT_NOTE) {
if ($action == 'editconditions') {
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id');
} else {
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
@ -418,18 +418,18 @@ if ($object->id > 0)
print '<table class="nobordernopadding centpercent"><tr><td>';
print $langs->trans('DateMaxPayment');
print '</td>';
if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && !empty($object->brouillon) && $user->rights->facture->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editpaymentterm&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
if ($object->type != $object::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && !empty($object->brouillon) && $user->rights->facture->creer) {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editpaymentterm&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
if ($object->type != $object::TYPE_CREDIT_NOTE)
{
if ($object->type != $object::TYPE_CREDIT_NOTE) {
$duedate = $object->date_lim_reglement;
if ($type == 'bank-transfer') {
$duedate = $object->date_echeance;
}
if ($action == 'editpaymentterm')
{
if ($action == 'editpaymentterm') {
$form->form_date($_SERVER['PHP_SELF'].'?id='.$object->id, $duedate, 'paymentterm');
} else {
print dol_print_date($duedate, 'day');
@ -447,11 +447,12 @@ if ($object->id > 0)
print '<table class="nobordernopadding centpercent"><tr><td>';
print $langs->trans('PaymentMode');
print '</td>';
if ($action != 'editmode' && !empty($object->brouillon) && $user->rights->facture->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
if ($action != 'editmode' && !empty($object->brouillon) && $user->rights->facture->creer) {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
if ($action == 'editmode')
{
if ($action == 'editmode') {
$form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id');
} else {
$form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
@ -463,12 +464,12 @@ if ($object->id > 0)
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
print $langs->trans('BankAccount');
print '<td>';
if (($action != 'editbankaccount') && $user->rights->commande->creer && !empty($object->brouillon))
if (($action != 'editbankaccount') && $user->rights->commande->creer && !empty($object->brouillon)) {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&amp;id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
if ($action == 'editbankaccount')
{
if ($action == 'editbankaccount') {
$form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
} else {
$form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
@ -487,7 +488,9 @@ if ($object->id > 0)
print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
if (!empty($bac->iban)) {
if ($bac->verif() <= 0) print img_warning('Error on default bank number for IBAN : '.$bac->error_message);
if ($bac->verif() <= 0) {
print img_warning('Error on default bank number for IBAN : '.$bac->error_message);
}
} else {
print img_warning($langs->trans("NoDefaultIBANFound"));
}
@ -503,8 +506,7 @@ if ($object->id > 0)
print '<table class="border centpercent tableforfield">';
if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))
{
if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) {
// Multicurrency Amount HT
print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';
print '<td class="nowrap">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
@ -530,31 +532,27 @@ if ($object->id > 0)
print '</tr>';
// Amount Local Taxes
if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) // Localtax1
{
if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) { // Localtax1
print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
print '<td class="nowrap">'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
}
if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) // Localtax2
{
if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) { // Localtax2
print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
print '<td class=nowrap">'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
}
// Revenue stamp
if ($selleruserevenustamp) // Test company use revenue stamp
{
if ($selleruserevenustamp) { // Test company use revenue stamp
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('RevenueStamp');
print '</td>';
if ($action != 'editrevenuestamp' && !empty($object->brouillon) && $user->rights->facture->creer)
{
if ($action != 'editrevenuestamp' && !empty($object->brouillon) && $user->rights->facture->creer) {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrevenuestamp&amp;facid='.$object->id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td>';
print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency);
print '</td></tr>';
}
@ -597,8 +595,7 @@ if ($object->id > 0)
$sql .= " ORDER BY pfd.date_demande DESC";
$result_sql = $db->query($sql);
if ($result_sql)
{
if ($result_sql) {
$num = $db->num_rows($result_sql);
$numopen = $num;
} else {
@ -618,10 +615,11 @@ if ($object->id > 0)
$sql .= " AND pfd.ext_payment_id IS NULL";
$result_sql = $db->query($sql);
if ($result_sql)
{
if ($result_sql) {
$obj = $db->fetch_object($result_sql);
if ($obj) $pending = $obj->amount;
if ($obj) {
$pending = $obj->amount;
}
} else {
dol_print_error($db);
}
@ -641,12 +639,9 @@ if ($object->id > 0)
}
// Add a transfer request
if ($object->statut > $object::STATUS_DRAFT && $object->paye == 0 && $num == 0)
{
if ($resteapayer > 0)
{
if ($user_perms)
{
if ($object->statut > $object::STATUS_DRAFT && $object->paye == 0 && $num == 0) {
if ($resteapayer > 0) {
if ($user_perms) {
$remaintopaylesspendingdebit = $resteapayer - $pending;
print '<form method="POST" action="">';
@ -665,10 +660,12 @@ if ($object->id > 0)
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AmountMustBePositive")).'">'.$buttonlabel.'</a>';
}
} else {
if ($num == 0)
{
if ($object->statut > $object::STATUS_DRAFT) print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AlreadyPaid")).'">'.$buttonlabel.'</a>';
else print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("Draft")).'">'.$buttonlabel.'</a>';
if ($num == 0) {
if ($object->statut > $object::STATUS_DRAFT) {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("AlreadyPaid")).'">'.$buttonlabel.'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("Draft")).'">'.$buttonlabel.'</a>';
}
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("RequestAlreadyDone")).'">'.$buttonlabel.'</a>';
}
@ -722,15 +719,13 @@ if ($object->id > 0)
$result_sql = $db->query($sql);
$num = 0;
if ($result_sql)
{
if ($result_sql) {
$i = 0;
$tmpuser = new User($db);
$num = $db->num_rows($result);
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($result_sql);
$tmpuser->id = $obj->user_id;
@ -788,16 +783,14 @@ if ($object->id > 0)
$sql .= " ORDER BY pfd.date_demande DESC";
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$numclosed = $num;
$i = 0;
$tmpuser = new User($db);
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($result);
$tmpuser->id = $obj->user_id;
@ -819,8 +812,7 @@ if ($object->id > 0)
print '<td class="center">'.price($obj->amount).'</td>';
print '<td class="center">';
if ($obj->fk_prelevement_bons > 0)
{
if ($obj->fk_prelevement_bons > 0) {
$withdrawreceipt = new BonPrelevement($db);
$withdrawreceipt->id = $obj->fk_prelevement_bons;
$withdrawreceipt->ref = $obj->ref;
@ -838,8 +830,9 @@ if ($object->id > 0)
$i++;
}
if (!$numopen && !$numclosed)
if (!$numopen && !$numclosed) {
print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
}
$db->free($result);
} else {

View File

@ -32,7 +32,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php';
if (!empty($conf->category->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
if (!empty($conf->category->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
}
$WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
@ -41,8 +43,12 @@ $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
$langs->loadLangs(array('bills', 'companies', 'other'));
$mode = GETPOST("mode") ?GETPOST("mode") : 'customer';
if ($mode == 'customer' && !$user->rights->facture->lire) accessforbidden();
if ($mode == 'supplier' && !$user->rights->fournisseur->facture->lire) accessforbidden();
if ($mode == 'customer' && !$user->rights->facture->lire) {
accessforbidden();
}
if ($mode == 'supplier' && !$user->rights->fournisseur->facture->lire) {
accessforbidden();
}
$object_status = GETPOST('object_status', 'intcomma');
$typent_id = GETPOST('typent_id', 'int');
@ -52,23 +58,27 @@ $userid = GETPOST('userid', 'int');
$socid = GETPOST('socid', 'int');
$custcats = GETPOST('custcats', 'array');
// Security check
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
$nowyear = strftime("%Y", dol_now());
$year = GETPOST('year') > 0 ? GETPOST('year', 'int') : $nowyear;
if (!empty($conf->global->INVOICE_STATS_GRAPHS_SHOW_2_YEARS)) $startyear = $year - 2;
else $startyear = $year - 1;
if (!empty($conf->global->INVOICE_STATS_GRAPHS_SHOW_2_YEARS)) {
$startyear = $year - 2;
} else {
$startyear = $year - 1;
}
$endyear = $year;
/*
* View
*/
if (!empty($conf->category->enabled)) $langs->load('categories');
if (!empty($conf->category->enabled)) {
$langs->load('categories');
}
$form = new Form($db);
$formcompany = new FormCompany($db);
$formother = new FormOther($db);
@ -79,8 +89,7 @@ $picto = 'bill';
$title = $langs->trans("BillsStatistics");
$dir = $conf->facture->dir_temp;
if ($mode == 'supplier')
{
if ($mode == 'supplier') {
$picto = 'supplier_invoice';
$title = $langs->trans("BillsStatisticsSuppliers");
$dir = $conf->fournisseur->facture->dir_temp;
@ -92,17 +101,19 @@ print load_fiche_titre($title, '', $picto);
dol_mkdir($dir);
$stats = new FactureStats($db, $socid, $mode, ($userid > 0 ? $userid : 0), ($typent_id > 0 ? $typent_id : 0), ($categ_id > 0 ? $categ_id : 0));
if ($mode == 'customer')
{
if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND f.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
if ($mode == 'customer') {
if ($object_status != '' && $object_status >= 0) {
$stats->where .= ' AND f.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
}
if (is_array($custcats) && !empty($custcats)) {
$stats->from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_societe as cat ON (f.fk_soc = cat.fk_soc)';
$stats->where .= ' AND cat.fk_categorie IN ('.implode(',', $custcats).')';
}
}
if ($mode == 'supplier')
{
if ($object_status != '' && $object_status >= 0) $stats->where .= ' AND f.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
if ($mode == 'supplier') {
if ($object_status != '' && $object_status >= 0) {
$stats->where .= ' AND f.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
}
}
// Build graphic number of object
@ -111,17 +122,19 @@ $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
//var_dump($data);
$filenamenb = $dir."/invoicesnbinyear-".$year.".png";
if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$year.'.png';
if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesnbinyear-'.$year.'.png';
if ($mode == 'customer') {
$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesnbinyear-'.$year.'.png';
}
if ($mode == 'supplier') {
$fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesnbinyear-'.$year.'.png';
}
$px1 = new DolGraph();
$mesg = $px1->isGraphKo();
if (!$mesg)
{
if (!$mesg) {
$px1->SetData($data);
$i = $startyear; $legend = array();
while ($i <= $endyear)
{
while ($i <= $endyear) {
$legend[] = $i;
$i++;
}
@ -144,17 +157,19 @@ $data = $stats->getAmountByMonthWithPrevYear($endyear, $startyear);
// $data = array(array('Lib',val1,val2,val3),...)
$filenameamount = $dir."/invoicesamountinyear-".$year.".png";
if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$year.'.png';
if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesamountinyear-'.$year.'.png';
if ($mode == 'customer') {
$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&amp;file=invoicesamountinyear-'.$year.'.png';
}
if ($mode == 'supplier') {
$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesamountinyear-'.$year.'.png';
}
$px2 = new DolGraph();
$mesg = $px2->isGraphKo();
if (!$mesg)
{
if (!$mesg) {
$px2->SetData($data);
$i = $startyear; $legend = array();
while ($i <= $endyear)
{
while ($i <= $endyear) {
$legend[] = $i;
$i++;
}
@ -175,25 +190,30 @@ if (!$mesg)
$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
if (!$user->rights->societe->client->voir || $user->socid)
{
if (!$user->rights->societe->client->voir || $user->socid) {
$filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
if ($mode == 'customer') {
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
}
if ($mode == 'supplier') {
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
}
} else {
$filename_avg = $dir.'/ordersaverage-'.$year.'.png';
if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
if ($mode == 'customer') {
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
}
if ($mode == 'supplier') {
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
}
}
$px3 = new DolGraph();
$mesg = $px3->isGraphKo();
if (!$mesg)
{
if (!$mesg) {
$px3->SetData($data);
$i = $startyear; $legend = array();
while ($i <= $endyear)
{
while ($i <= $endyear) {
$legend[] = $i;
$i++;
}
@ -218,7 +238,9 @@ $arrayyears = array();
foreach ($data as $val) {
$arrayyears[$val['year']] = $val['year'];
}
if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
if (!count($arrayyears)) {
$arrayyears[$nowyear] = $nowyear;
}
$h = 0;
@ -228,8 +250,12 @@ $head[$h][1] = $langs->trans("ByMonthYear");
$head[$h][2] = 'byyear';
$h++;
if ($mode == 'customer') $type = 'invoice_stats';
if ($mode == 'supplier') $type = 'supplier_invoice_stats';
if ($mode == 'customer') {
$type = 'invoice_stats';
}
if ($mode == 'supplier') {
$type = 'supplier_invoice_stats';
}
complete_head_from_modules($conf, $langs, null, $head, $h, $type);
@ -256,8 +282,12 @@ print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
// Company
print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
if ($mode == 'customer') $filter = 's.client in (1,2,3)';
if ($mode == 'supplier') $filter = 's.fournisseur = 1';
if ($mode == 'customer') {
$filter = 's.client in (1,2,3)';
}
if ($mode == 'supplier') {
$filter = 's.fournisseur = 1';
}
print $form->selectarray('socid', $companies, $socid, 1, 0, 0, 'style="width: 95%"', 0, 0, 0, '', '', 1);
print '</td></tr>';
@ -265,18 +295,18 @@ print '</td></tr>';
print '<tr><td>'.$langs->trans("ThirdPartyType").'</td><td>';
$sortparam_typent = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam_typent, '', 1);
if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
if ($user->admin) {
print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
}
print '</td></tr>';
// Category
if (!empty($conf->category->enabled)) {
if ($mode == 'customer')
{
if ($mode == 'customer') {
$cat_type = Categorie::TYPE_CUSTOMER;
$cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Customer"));
}
if ($mode == 'supplier')
{
if ($mode == 'supplier') {
$cat_type = Categorie::TYPE_SUPPLIER;
$cat_label = $langs->trans("Category").' '.lcfirst($langs->trans("Supplier"));
}
@ -293,21 +323,23 @@ print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0
print '</td></tr>';
// Status
print '<tr><td class="left">'.$langs->trans("Status").'</td><td class="left">';
if ($mode == 'customer')
{
if ($mode == 'customer') {
$liststatus = array('0'=>$langs->trans("BillStatusDraft"), '1'=>$langs->trans("BillStatusNotPaid"), '2'=>$langs->trans("BillStatusPaid"), '1,2'=>$langs->trans("BillStatusNotPaid").' / '.$langs->trans("BillStatusPaid"), '3'=>$langs->trans("BillStatusCanceled"));
print $form->selectarray('object_status', $liststatus, $object_status, 1);
}
if ($mode == 'supplier')
{
if ($mode == 'supplier') {
$liststatus = array('0'=>$langs->trans("BillStatusDraft"), '1'=>$langs->trans("BillStatusNotPaid"), '2'=>$langs->trans("BillStatusPaid"));
print $form->selectarray('object_status', $liststatus, $object_status, 1);
}
print '</td></tr>';
// Year
print '<tr><td>'.$langs->trans("Year").'</td><td>';
if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
if (!in_array($year, $arrayyears)) {
$arrayyears[$year] = $year;
}
if (!in_array($nowyear, $arrayyears)) {
$arrayyears[$nowyear] = $nowyear;
}
arsort($arrayyears);
print $form->selectarray('year', $arrayyears, $year, 0);
print '</td></tr>';
@ -329,11 +361,9 @@ print '<td class="right">%</td>';
print '</tr>';
$oldyear = 0;
foreach ($data as $val)
{
foreach ($data as $val) {
$year = $val['year'];
while ($year && $oldyear > $year + 1)
{ // If we have empty year
while ($year && $oldyear > $year + 1) { // If we have empty year
$oldyear--;
print '<tr class="oddeven" height="24">';
@ -367,7 +397,9 @@ print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
// Show graphs
print '<table class="border centpercent"><tr class="pair nohover"><td align="center">';
if ($mesg) { print $mesg; } else {
if ($mesg) {
print $mesg;
} else {
print $px1->show();
print "<br>\n";
print $px2->show();

View File

@ -18,8 +18,7 @@
*/
// Protection to avoid direct call of template
if (empty($conf) || !is_object($conf))
{
if (empty($conf) || !is_object($conf)) {
print "Error, template page can't be called as URL";
exit;
}
@ -38,12 +37,13 @@ $linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date', 'desc', 0, 0, 1)
$total = 0;
$ilink = 0;
foreach ($linkedObjectBlock as $key => $objectlink)
{
foreach ($linkedObjectBlock as $key => $objectlink) {
$ilink++;
$trclass = 'oddeven';
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass .= ' liste_sub_total';
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) {
$trclass .= ' liste_sub_total';
}
print '<tr class="'.$trclass.'" data-element="'.$objectlink->element.'" data-id="'.$objectlink->id.'" >';
print '<td class="linkedcol-element">';
switch ($objectlink->type) {
@ -73,7 +73,9 @@ foreach ($linkedObjectBlock as $key => $objectlink)
print '<td class="linkedcol-amount right">';
if ($user->rights->facture->lire) {
$sign = 1;
if ($object->type == Facture::TYPE_CREDIT_NOTE) $sign = -1;
if ($object->type == Facture::TYPE_CREDIT_NOTE) {
$sign = -1;
}
if ($objectlink->statut != 3) {
// If not abandonned
$total = $total + $sign * $objectlink->total_ht;
@ -87,8 +89,7 @@ foreach ($linkedObjectBlock as $key => $objectlink)
print '<td class="linkedcol-action right"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=dellink&dellinkid='.$key.'">'.img_picto($langs->transnoentitiesnoconv("RemoveLink"), 'unlink').'</a></td>';
print "</tr>\n";
}
if (count($linkedObjectBlock) > 1)
{
if (count($linkedObjectBlock) > 1) {
print '<tr class="liste_total '.(empty($noMoreLinkedObjectBlockAfter) ? 'liste_sub_total' : '').'">';
print '<td>'.$langs->trans("Total").'</td>';
print '<td></td>';

View File

@ -18,8 +18,7 @@
*/
// Protection to avoid direct call of template
if (empty($conf) || !is_object($conf))
{
if (empty($conf) || !is_object($conf)) {
print "Error, template page can't be called as URL";
exit;
}
@ -38,16 +37,17 @@ $langs->load("bills");
$total = 0;
$ilink = 0;
foreach ($linkedObjectBlock as $key => $objectlink)
{
foreach ($linkedObjectBlock as $key => $objectlink) {
$ilink++;
$trclass = 'oddeven';
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass .= ' liste_sub_total';
if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) {
$trclass .= ' liste_sub_total';
}
?>
<tr class="<?php echo $trclass; ?>" >
<td class="linkedcol-element"><?php echo $langs->trans("RepeatableInvoice"); ?></td>
<td class="linkedcol-name"><!-- nowraponall because ref is a label --><?php echo $objectlink->getNomUrl(1); ?></td>
<td class="linkedcol-element"><?php echo $langs->trans("RepeatableInvoice"); ?></td>
<td class="linkedcol-name"><!-- nowraponall because ref is a label --><?php echo $objectlink->getNomUrl(1); ?></td>
<td class="linkedcol-ref" align="center"></td>
<td class="linkedcol-date" align="center"><?php echo dol_print_date($objectlink->date_when, 'day'); ?></td>
<td class="linkedcol-amount right"><?php
@ -61,19 +61,18 @@ foreach ($linkedObjectBlock as $key => $objectlink)
</tr>
<?php
}
if (count($linkedObjectBlock) > 1)
{
if (count($linkedObjectBlock) > 1) {
?>
<tr class="liste_total <?php echo (empty($noMoreLinkedObjectBlockAfter) ? 'liste_sub_total' : ''); ?>">
<td><?php echo $langs->trans("Total"); ?></td>
<td></td>
<td align="center"></td>
<td align="center"></td>
<td class="right"><?php echo price($total); ?></td>
<td class="right"></td>
<td class="right"></td>
</tr>
<?php
<tr class="liste_total <?php echo (empty($noMoreLinkedObjectBlockAfter) ? 'liste_sub_total' : ''); ?>">
<td><?php echo $langs->trans("Total"); ?></td>
<td></td>
<td align="center"></td>
<td align="center"></td>
<td class="right"><?php echo price($total); ?></td>
<td class="right"></td>
<td class="right"></td>
</tr>
<?php
}
print "<!-- END PHP TEMPLATE -->\n";

View File

@ -47,16 +47,16 @@ require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'
// Load translation files required by the page
$langs->loadLangs(array('compta', 'bills'));
if (!empty($conf->commande->enabled))
if (!empty($conf->commande->enabled)) {
$langs->load("orders");
}
$action = GETPOST('action', 'aZ09');
$bid = GETPOST('bid', 'int');
// Security check
$socid = '';
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
@ -89,37 +89,35 @@ print load_fiche_titre($langs->trans("AccountancyTreasuryArea"), '', 'bill');
print '<div class="fichecenter"><div class="fichethirdleft">';
if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
{
if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo
// Search customer invoices
if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
{
if (!empty($conf->facture->enabled) && $user->rights->facture->lire) {
$listofsearchfields['search_invoice'] = array('text'=>'CustomerInvoice');
}
// Search supplier invoices
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->lire)
{
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->lire) {
$listofsearchfields['search_supplier_invoice'] = array('text'=>'SupplierInvoice');
}
if (!empty($conf->don->enabled) && $user->rights->don->lire)
{
if (!empty($conf->don->enabled) && $user->rights->don->lire) {
$langs->load("donations");
$listofsearchfields['search_donation'] = array('text'=>'Donation');
}
if (count($listofsearchfields))
{
if (count($listofsearchfields)) {
print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder nohover centpercent">';
$i = 0;
foreach ($listofsearchfields as $key => $value)
{
if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
foreach ($listofsearchfields as $key => $value) {
if ($i == 0) {
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
}
print '<tr '.$bc[false].'>';
print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'"></td>';
if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
if ($i == 0) {
print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
}
print '</tr>';
$i++;
}
@ -134,8 +132,7 @@ if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useles
/**
* Draft customers invoices
*/
if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
{
if (!empty($conf->facture->enabled) && $user->rights->facture->lire) {
$tmpinvoice = new Facture($db);
$sql = "SELECT f.rowid, f.ref, f.datef as date, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.ref_client";
@ -144,15 +141,20 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql .= ", s.rowid as socid, s.email";
$sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
$sql .= ", cc.rowid as country_id, cc.code as country_code";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", sc.fk_soc, sc.fk_user ";
}
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
$sql .= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid)
{
if ($socid) {
$sql .= " AND f.fk_soc = $socid";
}
// Add where from hooks
@ -163,7 +165,9 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total, f.tva, f.total_ttc, f.ref_client, f.type, f.fk_statut, f.paye,";
$sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
$sql .= " cc.rowid, cc.code";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user";
if (!$user->rights->societe->client->voir && !$socid) {
$sql.= ", sc.fk_soc, sc.fk_user";
}
// Add Group from hooks
$parameters = array();
@ -172,8 +176,7 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
print '<div class="div-table-responsive-no-min">';
@ -188,15 +191,13 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
print '</th>';
print '</tr>';
if ($num)
{
if ($num) {
$companystatic = new Societe($db);
$i = 0;
$othernb = 0;
$tot_ttc = 0;
while ($i < $num && $i < $conf->liste_limit)
{
while ($i < $num && $i < $conf->liste_limit) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
@ -264,8 +265,7 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
/**
* Draft suppliers invoices
*/
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire)
{
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) {
$facturesupplierstatic = new FactureFournisseur($db);
$sql = "SELECT f.ref, f.rowid, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.fk_statut as status, f.paye";
@ -274,19 +274,24 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
$sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
$sql .= ", cc.rowid as country_id, cc.code as country_code";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
$sql .= " AND f.entity IN (".getEntity('invoice').')';
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
$sql .= $hookmanager->resPrint;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
print '<div class="div-table-responsive-no-min">';
@ -301,15 +306,13 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
print '</th>';
print '</tr>';
if ($num)
{
if ($num) {
$companystatic = new Societe($db);
$i = 0;
$othernb = 0;
$tot_ttc = 0;
while ($i < $num && $i < $conf->liste_limit)
{
while ($i < $num && $i < $conf->liste_limit) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
@ -378,8 +381,7 @@ print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
// Latest modified customer invoices
if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
{
if (!empty($conf->facture->enabled) && $user->rights->facture->lire) {
$langs->load("boxes");
$tmpinvoice = new Facture($db);
@ -392,11 +394,17 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql .= ", sum(pf.amount) as am";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays, ".MAIN_DB_PREFIX."facture as f";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.rowid = f.fk_soc";
$sql .= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhereCustomerLastModified', $parameters);
@ -409,8 +417,7 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql .= $db->plimit($max, 0);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$othernb = 0;
@ -418,16 +425,16 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastCustomerBills", $max).'</th>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<th class="right">'.$langs->trans("AmountHT").'</th>';
}
print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
print '<th width="16">&nbsp;</th>';
print '</tr>';
if ($num)
{
if ($num) {
$total_ttc = $totalam = $total = 0;
while ($i < $num && $i < $conf->liste_limit)
{
while ($i < $num && $i < $conf->liste_limit) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
@ -483,7 +490,9 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
print '<td class="left">';
print $thirdpartystatic->getNomUrl(1, 'customer', 44);
print '</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="nowrap right">'.price($obj->total_ht).'</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<td class="nowrap right">'.price($obj->total_ht).'</td>';
}
print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
print '<td class="right">'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
@ -505,7 +514,9 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
}
} else {
$colspan = 5;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
$colspan++;
}
print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
}
print '</table></div><br>';
@ -518,8 +529,7 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
// Last modified supplier invoices
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire)
{
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) {
$langs->load("boxes");
$facstatic = new FactureFournisseur($db);
@ -530,11 +540,17 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
$sql .= ", SUM(pf.amount) as am";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.rowid = ff.fk_soc";
$sql .= " AND ff.entity = ".$conf->entity;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND ff.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND ff.fk_soc = ".$socid;
}
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
@ -546,26 +562,25 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
$sql .= $db->plimit($max, 0);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max).'</th>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<th class="right">'.$langs->trans("AmountHT").'</th>';
}
print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
print '<th width="16">&nbsp;</th>';
print "</tr>\n";
if ($num)
{
if ($num) {
$i = 0;
$total = $total_ttc = $totalam = 0;
$othernb = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
@ -602,7 +617,9 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
print '<td class="nowrap tdoverflowmax100">';
print $thirdpartystatic->getNomUrl(1, 'supplier');
print '</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<td class="right">'.price($obj->total_ht).'</td>';
}
print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
print '<td class="right">'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
print '<td>'.$facstatic->getLibStatut(3).'</td>';
@ -622,7 +639,9 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
}
} else {
$colspan = 5;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
$colspan++;
}
print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
}
print '</table></div><br>';
@ -634,8 +653,7 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
// Latest donations
if (!empty($conf->don->enabled) && $user->rights->don->lire)
{
if (!empty($conf->don->enabled) && $user->rights->don->lire) {
include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
$langs->load("boxes");
@ -653,8 +671,7 @@ if (!empty($conf->don->enabled) && $user->rights->don->lire)
$sql .= $db->plimit($max, 0);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
@ -669,12 +686,10 @@ if (!empty($conf->don->enabled) && $user->rights->don->lire)
print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
print '<th width="16">&nbsp;</th>';
print '</tr>';
if ($num)
{
if ($num) {
$total_ttc = $totalam = $total = 0;
while ($i < $num && $i < $max)
{
while ($i < $num && $i < $max) {
$objp = $db->fetch_object($result);
if ($i >= $max) {
@ -694,7 +709,9 @@ if (!empty($conf->don->enabled) && $user->rights->don->lire)
$donationstatic->status = $objp->status;
$label = $donationstatic->getFullName($langs);
if ($objp->societe) $label .= ($label ? ' - ' : '').$objp->societe;
if ($objp->societe) {
$label .= ($label ? ' - ' : '').$objp->societe;
}
print '<tr class="oddeven tdoverflowmax100">';
print '<td>'.$donationstatic->getNomUrl(1).'</td>';
@ -718,16 +735,16 @@ if (!empty($conf->don->enabled) && $user->rights->don->lire)
print '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
}
print '</table></div><br>';
} else dol_print_error($db);
} else {
dol_print_error($db);
}
}
/**
* Social contributions to pay
*/
if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
{
if (!$socid)
{
if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire) {
if (!$socid) {
$chargestatic = new ChargeSociales($db);
$sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
@ -746,8 +763,7 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
$sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
print '<div class="div-table-responsive-no-min">';
@ -759,14 +775,12 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
print '<th class="right">'.$langs->trans("Paid").'</th>';
print '<th align="center" width="16">&nbsp;</th>';
print '</tr>';
if ($num)
{
if ($num) {
$i = 0;
$tot_ttc = 0;
$othernb = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
@ -822,8 +836,7 @@ if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
/*
* Customers orders to be billed
*/
if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user->rights->commande->lire && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER))
{
if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user->rights->commande->lire && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
$commandestatic = new Commande($db);
$langs->load("orders");
@ -834,14 +847,20 @@ if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user
$sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.total_tva, c.total_ttc,";
$sql .= " cc.rowid as country_id, cc.code as country_code";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= ", ".MAIN_DB_PREFIX."commande as c";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
$sql .= " WHERE c.fk_soc = s.rowid";
$sql .= " AND c.entity = ".$conf->entity;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND c.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND c.fk_soc = ".$socid;
}
$sql .= " AND c.fk_statut = ".Commande::STATUS_CLOSED;
$sql .= " AND c.facture = 0";
// Add where from hooks
@ -852,12 +871,10 @@ if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user
$sql .= " GROUP BY s.nom, s.email, s.rowid, s.code_client, s.code_compta, c.rowid, c.ref, c.facture, c.fk_statut, c.total_ht, c.total_tva, c.total_ttc, cc.rowid, cc.code";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
if ($num)
{
if ($num) {
$i = 0;
$othernb = 0;
@ -872,7 +889,9 @@ if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user
print '</a>';
print '</th>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<th class="right">'.$langs->trans("AmountHT").'</th>';
}
print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
print '<th class="right">'.$langs->trans("ToBill").'</th>';
print '<th align="center" width="16">&nbsp;</th>';
@ -880,8 +899,7 @@ if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user
$tot_ht = $tot_ttc = $tot_tobill = 0;
$societestatic = new Societe($db);
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
@ -930,7 +948,9 @@ if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user
print '<td class="nowrap tdoverflowmax100">';
print $societestatic->getNomUrl(1, 'customer');
print '</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<td class="right">'.price($obj->total_ht).'</td>';
}
print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
print '<td class="nowrap right">'.price($obj->total_ttc - $obj->tot_fttc).'</td>';
print '<td>'.$commandestatic->getLibStatut(3).'</td>';
@ -951,7 +971,9 @@ if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user
}
print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToBill").': '.price($tot_tobill).')</font> </td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($tot_ht).'</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<td class="right">'.price($tot_ht).'</td>';
}
print '<td class="nowrap right">'.price($tot_ttc).'</td>';
print '<td class="nowrap right">'.price($tot_tobill).'</td>';
print '<td>&nbsp;</td>';
@ -967,8 +989,7 @@ if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user
/*
* Unpaid customers invoices
*/
if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
{
if (!empty($conf->facture->enabled) && $user->rights->facture->lire) {
$tmpinvoice = new Facture($db);
$sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.datef, f.type, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.paye, f.tms";
@ -980,11 +1001,17 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql .= ", sum(pf.amount) as am";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays,".MAIN_DB_PREFIX."facture as f";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
$sql .= " AND f.entity IN (".getEntity('invoice').')';
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
@ -995,8 +1022,7 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
$sql .= " ORDER BY f.datef ASC, f.ref ASC";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$othernb = 0;
@ -1013,17 +1039,17 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
print '</th>';
print '<th class="right">'.$langs->trans("DateDue").'</th>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<th class="right">'.$langs->trans("AmountHT").'</th>';
}
print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
print '<th class="right">'.$langs->trans("Received").'</th>';
print '<th width="16">&nbsp;</th>';
print '</tr>';
if ($num)
{
if ($num) {
$societestatic = new Societe($db);
$total_ttc = $totalam = $total = 0;
while ($i < $num && $i < $conf->liste_limit)
{
while ($i < $num && $i < $conf->liste_limit) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
@ -1079,7 +1105,9 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
print $societestatic->getNomUrl(1, 'customer');
print '</td>';
print '<td class="right">'.dol_print_date($db->jdate($obj->datelimite), 'day').'</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<td class="right">'.price($obj->total_ht).'</td>';
}
print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
print '<td class="nowrap right">'.price($obj->am).'</td>';
print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
@ -1094,7 +1122,9 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
if ($othernb) {
$colspan = 6;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
$colspan++;
}
print '<tr class="oddeven">';
print '<td class="nowrap" colspan="'.$colspan.'">';
print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
@ -1104,14 +1134,18 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToTake").': '.price($total_ttc - $totalam).')</font> </td>';
print '<td>&nbsp;</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($total).'</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<td class="right">'.price($total).'</td>';
}
print '<td class="nowrap right">'.price($total_ttc).'</td>';
print '<td class="nowrap right">'.price($totalam).'</td>';
print '<td>&nbsp;</td>';
print '</tr>';
} else {
$colspan = 6;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
$colspan++;
}
print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
}
print '</table></div><br>';
@ -1124,8 +1158,7 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
/*
* Unpaid supplier invoices
*/
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire)
{
if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire) {
$facstatic = new FactureFournisseur($db);
$sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.type, ff.libelle as label, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye";
@ -1137,13 +1170,19 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
$sql .= ", sum(pf.amount) as am";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.rowid = ff.fk_soc";
$sql .= " AND ff.entity = ".$conf->entity;
$sql .= " AND ff.paye = 0";
$sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND ff.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND ff.fk_soc = ".$socid;
}
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
@ -1154,8 +1193,7 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
$sql .= " ORDER BY ff.date_lim_reglement ASC";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$othernb = 0;
@ -1173,18 +1211,18 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
print '</th>';
print '<th class="right">'.$langs->trans("DateDue").'</th>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<th class="right">'.$langs->trans("AmountHT").'</th>';
}
print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
print '<th class="right">'.$langs->trans("Paid").'</th>';
print '<th width="16">&nbsp;</th>';
print "</tr>\n";
$societestatic = new Societe($db);
if ($num)
{
if ($num) {
$i = 0;
$total = $total_ttc = $totalam = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($resql);
if ($i >= $max) {
@ -1219,7 +1257,9 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
print '</td>';
print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<td class="right">'.price($obj->total_ht).'</td>';
}
print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
print '<td class="nowrap right">'.price($obj->am).'</td>';
print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
@ -1232,7 +1272,9 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
if ($othernb) {
$colspan = 6;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
$colspan++;
}
print '<tr class="oddeven">';
print '<td class="nowrap" colspan="'.$colspan.'">';
print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
@ -1242,14 +1284,18 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToPay").': '.price($total_ttc - $totalam).')</font> </td>';
print '<td>&nbsp;</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($total).'</td>';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
print '<td class="right">'.price($total).'</td>';
}
print '<td class="nowrap right">'.price($total_ttc).'</td>';
print '<td class="nowrap right">'.price($totalam).'</td>';
print '<td>&nbsp;</td>';
print '</tr>';
} else {
$colspan = 6;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
$colspan++;
}
print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
}
print '</table></div><br>';
@ -1262,15 +1308,13 @@ if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SU
// TODO Mettre ici recup des actions en rapport avec la compta
$resql = 0;
if ($resql)
{
if ($resql) {
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><thcolspan="2">'.$langs->trans("TasksToDo").'</th>';
print "</tr>\n";
$i = 0;
while ($i < $db->num_rows($resql))
{
while ($i < $db->num_rows($resql)) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';

View File

@ -45,9 +45,15 @@ $date_endday = GETPOST('date_endday');
$date_endyear = GETPOST('date_endyear');
// Security check
if ($user->socid > 0) $socid = $user->socid;
if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat');
if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
if ($user->socid > 0) {
$socid = $user->socid;
}
if (!empty($conf->comptabilite->enabled)) {
$result = restrictedArea($user, 'compta', '', '', 'resultat');
}
if (!empty($conf->accounting->enabled)) {
$result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
}
/*
@ -70,8 +76,7 @@ $form = new Form($db);
$year_current = strftime("%Y", dol_now());
$pastmonth = strftime("%m", dol_now()) - 1;
$pastmonthyear = $year_current;
if ($pastmonth == 0)
{
if ($pastmonth == 0) {
$pastmonth = 12;
$pastmonthyear--;
}
@ -79,8 +84,7 @@ if ($pastmonth == 0)
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
$date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
$date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
}
@ -90,8 +94,11 @@ $periodlink = '';
$exportlink = '';
$builddate = dol_now();
$description = $langs->trans("DescPurchasesJournal").'<br>';
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans("DepositsAreNotIncluded");
else $description .= $langs->trans("DepositsAreIncluded");
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$description .= $langs->trans("DepositsAreNotIncluded");
} else {
$description .= $langs->trans("DepositsAreIncluded");
}
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink);
@ -111,16 +118,22 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product";
$sql .= " JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON f.rowid = fd.fk_facture_fourn";
$sql .= " JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
$sql .= " WHERE f.fk_statut > 0 AND f.entity IN (".getEntity('invoice').")";
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2)";
else $sql .= " AND f.type IN (0,1,2,3)";
if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$sql .= " AND f.type IN (0,1,2)";
} else {
$sql .= " AND f.type IN (0,1,2,3)";
}
if ($date_start && $date_end) {
$sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
}
// TODO Find a better trick to avoid problem with some mysql installations
if (in_array($db->type, array('mysql', 'mysqli'))) $db->query('SET SQL_BIG_SELECTS=1');
if (in_array($db->type, array('mysql', 'mysqli'))) {
$db->query('SET SQL_BIG_SELECTS=1');
}
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
// les variables
$cptfour = (($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER != "") ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef"));
@ -135,16 +148,17 @@ if ($result)
$tabcompany = array();
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($result);
// contrôles
$compta_soc = (($obj->code_compta_fournisseur != "") ? $obj->code_compta_fournisseur : $cptfour);
$compta_prod = $obj->accountancy_code_buy;
if (empty($compta_prod))
{
if ($obj->product_type == 0) $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
else $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
if (empty($compta_prod)) {
if ($obj->product_type == 0) {
$compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
} else {
$compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
}
}
$compta_tva = (!empty($obj->account_tva) ? $obj->account_tva : $cpttva);
$compta_localtax1 = (!empty($obj->account_localtax1) ? $obj->account_localtax1 : $langs->trans("CodeNotDef"));
@ -161,9 +175,11 @@ if ($result)
$tabfac[$obj->rowid]["lib"] = $obj->label;
$tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc;
$tabht[$obj->rowid][$compta_prod] += $obj->total_ht;
if ($obj->recuperableonly != 1) $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
if ($obj->recuperableonly != 1) {
$tabtva[$obj->rowid][$compta_tva] += $obj->total_tva;
}
$tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
$tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
$tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
$tabcompany[$obj->rowid] = array('id'=>$obj->socid, 'name'=>$obj->name);
$i++;
@ -188,8 +204,7 @@ print "</tr>\n";
$invoicestatic = new FactureFournisseur($db);
$companystatic = new Fournisseur($db);
foreach ($tabfac as $key => $val)
{
foreach ($tabfac as $key => $val) {
$invoicestatic->id = $key;
$invoicestatic->ref = $val["ref"];
$invoicestatic->type = $val["type"];
@ -222,19 +237,15 @@ foreach ($tabfac as $key => $val)
)
);
foreach ($lines as $line)
{
foreach ($line['var'] as $k => $mt)
{
if (isset($line['nomtcheck']) || $mt)
{
foreach ($lines as $line) {
foreach ($line['var'] as $k => $mt) {
if (isset($line['nomtcheck']) || $mt) {
print '<tr class="oddeven">';
print "<td>".dol_print_date($db->jdate($val["date"]))."</td>";
print "<td>".$invoicestatic->getNomUrl(1)."</td>";
print "<td>".$k."</td><td>".$line['label']."</td>";
if (isset($line['inv']))
{
if (isset($line['inv'])) {
print '<td class="right">'.($mt < 0 ?price(-$mt) : '')."</td>";
print '<td class="right">'.($mt >= 0 ?price($mt) : '')."</td>";
} else {

View File

@ -47,9 +47,15 @@ $date_endday = GETPOST('date_endday');
$date_endyear = GETPOST('date_endyear');
// Security check
if ($user->socid > 0) $socid = $user->socid;
if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat');
if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
if ($user->socid > 0) {
$socid = $user->socid;
}
if (!empty($conf->comptabilite->enabled)) {
$result = restrictedArea($user, 'compta', '', '', 'resultat');
}
if (!empty($conf->accounting->enabled)) {
$result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
}
/*
* Actions
@ -73,8 +79,7 @@ llxHeader('', $langs->trans("SellsJournal"), '', '', 0, 0, '', '', $morequery);
$year_current = strftime("%Y", dol_now());
$pastmonth = strftime("%m", dol_now()) - 1;
$pastmonthyear = $year_current;
if ($pastmonth == 0)
{
if ($pastmonth == 0) {
$pastmonth = 12;
$pastmonthyear--;
}
@ -82,8 +87,7 @@ if ($pastmonth == 0)
$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
$date_start = dol_get_first_day($pastmonthyear, $pastmonth, false); $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
}
@ -92,8 +96,11 @@ $periodlink = '';
$exportlink = '';
$builddate = dol_now();
$description = $langs->trans("DescSellsJournal").'<br>';
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans("DepositsAreNotIncluded");
else $description .= $langs->trans("DepositsAreIncluded");
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$description .= $langs->trans("DepositsAreNotIncluded");
} else {
$description .= $langs->trans("DepositsAreIncluded");
}
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink);
@ -119,15 +126,18 @@ if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
}
$sql .= " AND fd.product_type IN (0,1)";
if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
if ($date_start && $date_end) {
$sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
}
$sql .= " ORDER BY f.rowid";
// TODO Find a better trick to avoid problem with some mysql installations
if (in_array($db->type, array('mysql', 'mysqli'))) $db->query('SET SQL_BIG_SELECTS=1');
if (in_array($db->type, array('mysql', 'mysqli'))) {
$db->query('SET SQL_BIG_SELECTS=1');
}
$result = $db->query($sql);
if ($result)
{
if ($result) {
$tabfac = array();
$tabht = array();
$tabtva = array();
@ -139,19 +149,20 @@ if ($result)
$account_localtax2 = 0;
$num = $db->num_rows($result);
$i = 0;
$resligne = array();
while ($i < $num)
{
$obj = $db->fetch_object($result);
// les variables
$cptcli = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER != "") ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef"));
$compta_soc = (!empty($obj->code_compta) ? $obj->code_compta : $cptcli);
$i = 0;
$resligne = array();
while ($i < $num) {
$obj = $db->fetch_object($result);
// les variables
$cptcli = (($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER != "") ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef"));
$compta_soc = (!empty($obj->code_compta) ? $obj->code_compta : $cptcli);
$compta_prod = $obj->accountancy_code_sell;
if (empty($compta_prod))
{
if ($obj->product_type == 0) $compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
else $compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
if (empty($compta_prod)) {
if ($obj->product_type == 0) {
$compta_prod = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
} else {
$compta_prod = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
}
}
$cpttva = (!empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
$compta_tva = (!empty($obj->account_tva) ? $obj->account_tva : $cpttva);
@ -178,22 +189,34 @@ if ($result)
}
//la ligne facture
$tabfac[$obj->rowid]["date"] = $obj->datef;
$tabfac[$obj->rowid]["ref"] = $obj->ref;
$tabfac[$obj->rowid]["type"] = $obj->type;
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;
$tabfac[$obj->rowid]["date"] = $obj->datef;
$tabfac[$obj->rowid]["ref"] = $obj->ref;
$tabfac[$obj->rowid]["type"] = $obj->type;
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;
$tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
if ($obj->recuperableonly != 1) $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
$tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
$tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
$tabcompany[$obj->rowid] = array('id'=>$obj->socid, 'name'=>$obj->name, 'client'=>$obj->client);
$i++;
}
if ($obj->recuperableonly != 1) {
$tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
}
$tablocaltax1[$obj->rowid][$compta_localtax1] += $obj->total_localtax1;
$tablocaltax2[$obj->rowid][$compta_localtax2] += $obj->total_localtax2;
$tabcompany[$obj->rowid] = array('id'=>$obj->socid, 'name'=>$obj->name, 'client'=>$obj->client);
$i++;
}
} else {
dol_print_error($db);
}
@ -216,8 +239,7 @@ print "</tr>\n";
$invoicestatic = new Facture($db);
$companystatic = new Client($db);
foreach ($tabfac as $key => $val)
{
foreach ($tabfac as $key => $val) {
$invoicestatic->id = $key;
$invoicestatic->ref = $val["ref"];
$invoicestatic->type = $val["type"];
@ -251,19 +273,15 @@ foreach ($tabfac as $key => $val)
)
);
foreach ($lines as $line)
{
foreach ($line['var'] as $k => $mt)
{
if (isset($line['nomtcheck']) || $mt)
{
foreach ($lines as $line) {
foreach ($line['var'] as $k => $mt) {
if (isset($line['nomtcheck']) || $mt) {
print '<tr class="oddeven">';
print "<td>".dol_print_date($db->jdate($val["date"]))."</td>";
print "<td>".$invoicestatic->getNomUrl(1)."</td>";
print "<td>".$k."</td><td>".$line['label']."</td>";
if (isset($line['inv']))
{
if (isset($line['inv'])) {
print '<td class="right">'.($mt >= 0 ?price($mt) : '')."</td>";
print '<td class="right">'.($mt < 0 ?price(-$mt) : '')."</td>";
} else {

View File

@ -34,13 +34,17 @@ $langs->loadLangs(array('compta', 'banks', 'bills'));
$id = GETPOST("id", 'int');
$action = GETPOST("action", "alpha");
$refund = GETPOST("refund", "int");
if (empty($refund)) $refund = 0;
if (empty($refund)) {
$refund = 0;
}
$lttype = GETPOST('localTaxType', 'int');
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'tax', '', '', 'charges');
$object = new Localtax($db);
@ -53,14 +57,12 @@ $hookmanager->initHooks(array('localtaxvatcard', 'globalcard'));
* Actions
*/
if ($_POST["cancel"] == $langs->trans("Cancel") && !$id)
{
if ($_POST["cancel"] == $langs->trans("Cancel") && !$id) {
header("Location: list.php?localTaxType=".$lttype);
exit;
}
if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
{
if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) {
$db->begin();
$datev = dol_mktime(12, 0, 0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
@ -75,8 +77,7 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
$object->ltt = $lttype;
$ret = $object->addPayment($user);
if ($ret > 0)
{
if ($ret > 0) {
$db->commit();
header("Location: list.php?localTaxType=".$lttype);
exit;
@ -88,26 +89,23 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
}
//delete payment of localtax
if ($action == 'delete')
{
if ($action == 'delete') {
$result = $object->fetch($id);
if ($object->rappro == 0)
{
if ($object->rappro == 0) {
$db->begin();
$ret = $object->delete($user);
if ($ret > 0)
{
if ($object->fk_bank)
{
if ($ret > 0) {
if ($object->fk_bank) {
$accountline = new AccountLine($db);
$result = $accountline->fetch($object->fk_bank);
if ($result > 0) $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
if ($result > 0) {
$result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
}
}
if ($result >= 0)
{
if ($result >= 0) {
$db->commit();
header("Location: ".DOL_URL_ROOT.'/compta/localtax/list.php?localTaxType='.$object->ltt);
exit;
@ -131,11 +129,9 @@ if ($action == 'delete')
* View
*/
if ($id)
{
if ($id) {
$result = $object->fetch($id);
if ($result <= 0)
{
if ($result <= 0) {
dol_print_error($db);
exit;
}
@ -147,8 +143,7 @@ $title = $langs->trans("LT".$object->ltt)." - ".$langs->trans("Card");
$help_url = '';
llxHeader("", $title, $helpurl);
if ($action == 'create')
{
if ($action == 'create') {
print load_fiche_titre($langs->transcountry($lttype == 2 ? "newLT2Payment" : "newLT1Payment", $mysoc->country_code));
print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
@ -175,8 +170,7 @@ if ($action == 'create')
// Amount
print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
print '<tr><td class="fieldrequired">'.$langs->trans("Account").'</td><td>';
$form->select_comptes($_POST["accountid"], "accountid", 0, "courant=1", 2); // Affiche liste des comptes courant
print '</td></tr>';
@ -211,8 +205,7 @@ if ($action == 'create')
// View mode
if ($id)
{
if ($id) {
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$object->id;
$head[$h][1] = $langs->trans('Card');
@ -246,11 +239,9 @@ if ($id)
print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
if (!empty($conf->banque->enabled))
{
if ($object->fk_account > 0)
{
$bankline = new AccountLine($db);
if (!empty($conf->banque->enabled)) {
if ($object->fk_account > 0) {
$bankline = new AccountLine($db);
$bankline->fetch($object->fk_bank);
print '<tr>';
@ -278,8 +269,7 @@ if ($id)
* Action buttons
*/
print "<div class=\"tabsAction\">\n";
if ($object->rappro == 0)
{
if ($object->rappro == 0) {
print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';

View File

@ -122,19 +122,19 @@ class Localtax extends CommonObject
$sql .= " ".((int) $this->fk_user_modif);
$sql .= ")";
dol_syslog(get_class($this)."::create", LOG_DEBUG);
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."localtax");
// Call trigger
$result = $this->call_trigger('LOCALTAX_CREATE', $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
// End call triggers
if (!$error)
{
if (!$error) {
$this->db->commit();
return $this->id;
} else {
@ -184,22 +184,21 @@ class Localtax extends CommonObject
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$this->error = "Error ".$this->db->lasterror();
$error++;
}
if (!$error && !$notrigger)
{
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('LOCALTAX_MODIFY', $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
// End call triggers
}
if (!$error)
{
if (!$error) {
$this->db->commit();
return 1;
} else {
@ -239,10 +238,8 @@ class Localtax extends CommonObject
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -265,7 +262,7 @@ class Localtax extends CommonObject
return 1;
} else {
$this->error = "Error ".$this->db->lasterror();
$this->error = "Error ".$this->db->lasterror();
return -1;
}
}
@ -281,16 +278,17 @@ class Localtax extends CommonObject
{
// Call trigger
$result = $this->call_trigger('LOCALTAX_DELETE', $user);
if ($result < 0) return -1;
if ($result < 0) {
return -1;
}
// End call triggers
$sql = "DELETE FROM ".MAIN_DB_PREFIX."localtax";
$sql .= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$this->error = "Error ".$this->db->lasterror();
return -1;
}
@ -355,16 +353,13 @@ class Localtax extends CommonObject
// phpcs:enable
$sql = "SELECT sum(f.localtax) as amount";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1";
if ($year)
{
if ($year) {
$sql .= " AND f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' ";
}
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$ret = $obj->amount;
$this->db->free($result);
@ -392,16 +387,13 @@ class Localtax extends CommonObject
$sql = "SELECT sum(f.total_localtax) as total_localtax";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
if ($year)
{
if ($year) {
$sql .= " WHERE f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' ";
}
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$ret = $obj->total_localtax;
$this->db->free($result);
@ -430,16 +422,13 @@ class Localtax extends CommonObject
$sql = "SELECT sum(f.amount) as amount";
$sql .= " FROM ".MAIN_DB_PREFIX."localtax as f";
if ($year)
{
if ($year) {
$sql .= " WHERE f.datev >= '$year-01-01' AND f.datev <= '$year-12-31' ";
}
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$ret = $obj->amount;
$this->db->free($result);
@ -469,62 +458,64 @@ class Localtax extends CommonObject
// Check parameters
$this->amount = price2num($this->amount);
if (!$this->label)
{
if (!$this->label) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
return -3;
}
if ($this->amount <= 0)
{
if ($this->amount <= 0) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
return -4;
}
if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0))
{
if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0)) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account"));
return -5;
}
if (!empty($conf->banque->enabled) && (empty($this->paymenttype) || $this->paymenttype <= 0))
{
if (!empty($conf->banque->enabled) && (empty($this->paymenttype) || $this->paymenttype <= 0)) {
$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
return -5;
}
// Insertion dans table des paiement localtax
$sql = "INSERT INTO ".MAIN_DB_PREFIX."localtax (localtaxtype, datep, datev, amount";
if ($this->note) $sql .= ", note";
if ($this->label) $sql .= ", label";
if ($this->note) {
$sql .= ", note";
}
if ($this->label) {
$sql .= ", label";
}
$sql .= ", fk_user_creat, fk_bank";
$sql .= ") ";
$sql .= " VALUES (".$this->ltt.", '".$this->db->idate($this->datep)."',";
$sql .= "'".$this->db->idate($this->datev)."',".$this->amount;
if ($this->note) $sql .= ", '".$this->db->escape($this->note)."'";
if ($this->label) $sql .= ", '".$this->db->escape($this->label)."'";
if ($this->note) {
$sql .= ", '".$this->db->escape($this->note)."'";
}
if ($this->label) {
$sql .= ", '".$this->db->escape($this->label)."'";
}
$sql .= ", ".((int) $user->id).", NULL";
$sql .= ")";
dol_syslog(get_class($this)."::addPayment", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."localtax"); // TODO devrait s'appeler paiementlocaltax
if ($this->id > 0)
{
if ($this->id > 0) {
$ok = 1;
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
// Insertion dans llx_bank
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$acc = new Account($this->db);
$result = $acc->fetch($this->accountid);
if ($result <= 0) dol_print_error($this->db);
if ($result <= 0) {
dol_print_error($this->db);
}
$bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs($this->amount), '', '', $user);
// Mise a jour fk_bank dans llx_localtax. On connait ainsi la ligne de localtax qui a g<>n<EFBFBD>r<EFBFBD> l'<27>criture bancaire
if ($bank_line_id > 0)
{
if ($bank_line_id > 0) {
$this->update_fk_bank($bank_line_id);
} else {
$this->error = $acc->error;
@ -533,15 +524,13 @@ class Localtax extends CommonObject
// Mise a jour liens
$result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT.'/compta/localtax/card.php?id=', "(VATPayment)", "payment_vat");
if ($result < 0)
{
if ($result < 0) {
$this->error = $acc->error;
$ok = 0;
}
}
if ($ok)
{
if ($ok) {
$this->db->commit();
return $this->id;
} else {
@ -601,9 +590,15 @@ class Localtax extends CommonObject
$picto = 'payment';
if ($withpicto) $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
if ($withpicto && $withpicto != 2) $result .= ' ';
if ($withpicto != 2) $result .= $link.$this->ref.$linkend;
if ($withpicto) {
$result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
}
if ($withpicto && $withpicto != 2) {
$result .= ' ';
}
if ($withpicto != 2) {
$result .= $link.$this->ref.$linkend;
}
return $result;
}

View File

@ -37,8 +37,7 @@ $local = GETPOST('localTaxType', 'int');
// Date range
$year = GETPOST("year", "int");
if (empty($year))
{
if (empty($year)) {
$year_current = strftime("%Y", dol_now());
$year_start = $year_current;
} else {
@ -48,41 +47,60 @@ if (empty($year))
$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
// Quarter
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
$q = GETPOST("q");
if (empty($q))
{
if (GETPOST("month")) { $date_start = dol_get_first_day($year_start, GETPOST("month"), false); $date_end = dol_get_last_day($year_start, GETPOST("month"), false); } else {
if (empty($q)) {
if (GETPOST("month")) {
$date_start = dol_get_first_day($year_start, GETPOST("month"), false); $date_end = dol_get_last_day($year_start, GETPOST("month"), false);
} else {
$date_start = dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START, false);
if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) {
$date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
} elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) {
$date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
} elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) {
$date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
}
}
} else {
if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
if ($q == 1) {
$date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false);
}
if ($q == 2) {
$date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false);
}
if ($q == 3) {
$date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false);
}
if ($q == 4) {
$date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false);
}
}
}
$min = price2num(GETPOST("min", "alpha"));
if (empty($min)) $min = 0;
if (empty($min)) {
$min = 0;
}
// Define modetax (0 or 1)
// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
$modetax = $conf->global->TAX_MODE;
if (GETPOSTISSET("modetax")) $modetax = GETPOST("modetax", 'int');
if (empty($modetax)) $modetax = 0;
if (GETPOSTISSET("modetax")) {
$modetax = GETPOST("modetax", 'int');
}
if (empty($modetax)) {
$modetax = 0;
}
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'tax', '', '', 'charges');
if (empty($local))
{
if (empty($local)) {
accessforbidden('Parameter localTaxType is missing');
exit;
}
@ -98,9 +116,10 @@ $company_static = new Societe($db);
$morequerystring = '';
$listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
foreach ($listofparams as $param)
{
if (GETPOST($param) != '') $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
foreach ($listofparams as $param) {
if (GETPOST($param) != '') {
$morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
}
}
llxHeader('', '', '', '', 0, 0, '', '', $morequerystring);
@ -117,12 +136,13 @@ $fsearch .= '<input type="text" name="min" id="min" value="'.$min.'" size="6">';
$calc = $conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
// Affiche en-tete du rapport
if ($calc == 0 || $calc == 1) // Calculate on invoice for goods and services
{
if ($calc == 0 || $calc == 1) { // Calculate on invoice for goods and services
$calcmode = $calc == 0 ? $langs->trans("CalcModeLT".$local) : $langs->trans("CalcModeLT".$local."Rec");
$calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
if (!empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
if (!empty($conf->global->MAIN_MODULE_COMPTABILITE)) {
$description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
}
$description .= $fsearch;
$description .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
$builddate = dol_now();
@ -134,12 +154,13 @@ if ($calc == 0 || $calc == 1) // Calculate on invoice for goods and services
$productsup = $langs->trans("Description");
$amountsup = $langs->trans("AmountHT");
}
if ($calc == 2) // Invoice for goods, payment for services
{
if ($calc == 2) { // Invoice for goods, payment for services
$calcmode = $langs->trans("CalcModeLT2Debt");
$calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
if (!empty($conf->global->MAIN_MODULE_COMPTABILITE)) $description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
if (!empty($conf->global->MAIN_MODULE_COMPTABILITE)) {
$description .= '<br>'.$langs->trans("WarningDepositsNotIncluded");
}
$description .= $fsearch;
$description .= '<span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')</span>';
$builddate = dol_now();
@ -161,8 +182,7 @@ print '<div class="div-table-responsive">';
print '<table class="noborder centpercent">';
// IRPF that the customer has retained me
if ($calc == 0 || $calc == 2)
{
if ($calc == 0 || $calc == 2) {
print '<tr class="liste_titre">';
print '<td class="left">'.$langs->trans("Num").'</td>';
print '<td class="left">'.$langs->trans("Customer").'</td>';
@ -185,19 +205,14 @@ if ($calc == 0 || $calc == 2)
$hookmanager->initHooks(array('externalbalance'));
$reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if (is_array($coll_list))
{
if (is_array($coll_list)) {
$total = 0; $totalamount = 0;
$i = 1;
foreach ($coll_list as $coll)
{
if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0)
{
foreach ($coll_list as $coll) {
if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0) {
$intra = str_replace($find, $replace, $coll->tva_intra);
if (empty($intra))
{
if ($coll->assuj == '1')
{
if (empty($intra)) {
if ($coll->assuj == '1') {
$intra = $langs->trans('Unknown');
} else {
$intra = '';
@ -227,11 +242,13 @@ if ($calc == 0 || $calc == 2)
print '</tr>';
} else {
$langs->load("errors");
if ($coll_list == -1)
if ($coll_list == -1) {
print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
elseif ($coll_list == -2)
} elseif ($coll_list == -2) {
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
else print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
} else {
print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
}
}
}
@ -252,19 +269,14 @@ if ($calc == 0 || $calc == 1) {
$parameters["type"] = 'localtax'.$local;
$reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if (is_array($coll_list))
{
if (is_array($coll_list)) {
$total = 0; $totalamount = 0;
$i = 1;
foreach ($coll_list as $coll)
{
if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0)
{
foreach ($coll_list as $coll) {
if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0) {
$intra = str_replace($find, $replace, $coll->tva_intra);
if (empty($intra))
{
if ($coll->assuj == '1')
{
if (empty($intra)) {
if ($coll->assuj == '1') {
$intra = $langs->trans('Unknown');
} else {
$intra = '';
@ -294,11 +306,13 @@ if ($calc == 0 || $calc == 1) {
print '</tr>';
} else {
$langs->load("errors");
if ($coll_list == -1)
if ($coll_list == -1) {
print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
elseif ($coll_list == -2)
} elseif ($coll_list == -2) {
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
else print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
} else {
print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
}
}
}

View File

@ -37,8 +37,7 @@ $localTaxType = GETPOST('localTaxType', 'int');
// Date range
$year = GETPOST("year", "int");
if (empty($year))
{
if (empty($year)) {
$year_current = strftime("%Y", dol_now());
$year_start = $year_current;
} else {
@ -47,32 +46,46 @@ if (empty($year))
}
$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
$q = GETPOST("q", "int");
if (empty($q))
{
if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } else {
if (empty($q)) {
if (GETPOST("month", "int")) {
$date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false);
} else {
$date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false);
$date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
}
} else {
if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
if ($q == 1) {
$date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false);
}
if ($q == 2) {
$date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false);
}
if ($q == 3) {
$date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false);
}
if ($q == 4) {
$date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false);
}
}
}
// Define modetax (0 or 1)
// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
$modetax = $conf->global->TAX_MODE;
if (GETPOSTISSET("modetax")) $modetax = GETPOST("modetax", 'int');
if (empty($modetax)) $modetax = 0;
if (GETPOSTISSET("modetax")) {
$modetax = GETPOST("modetax", 'int');
}
if (empty($modetax)) {
$modetax = 0;
}
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'tax', '', '', 'charges');
@ -114,8 +127,7 @@ function pt($db, $sql, $date)
$mode = $obj->mode;
//print $obj->dm.' '.$obj->mode.' '.$previousmonth.' '.$previousmode;
if ($obj->mode == 'claimed' && !empty($previousmode))
{
if ($obj->mode == 'claimed' && !empty($previousmode)) {
print '<tr class="oddeven">';
print '<td class="nowrap">'.$previousmonth."</td>\n";
print '<td class="nowrap right">'.price($amountclaimed)."</td>\n";
@ -126,19 +138,16 @@ function pt($db, $sql, $date)
$amountpaid = 0;
}
if ($obj->mode == 'claimed')
{
if ($obj->mode == 'claimed') {
$amountclaimed = $obj->mm;
$totalclaimed = $totalclaimed + $amountclaimed;
}
if ($obj->mode == 'paid')
{
if ($obj->mode == 'paid') {
$amountpaid = $obj->mm;
$totalpaid = $totalpaid + $amountpaid;
}
if ($obj->mode == 'paid')
{
if ($obj->mode == 'paid') {
print '<tr class="oddeven">';
print '<td class="nowrap">'.$obj->dm."</td>\n";
print '<td class="nowrap right">'.price($amountclaimed)."</td>\n";
@ -156,8 +165,7 @@ function pt($db, $sql, $date)
$i++;
}
if ($mode == 'claimed' && !empty($previousmode))
{
if ($mode == 'claimed' && !empty($previousmode)) {
print '<tr class="oddeven">';
print '<td class="nowrap">'.$previousmonth."</td>\n";
print '<td class="nowrap right">'.price($amountclaimed)."</td>\n";
@ -181,8 +189,7 @@ function pt($db, $sql, $date)
}
}
if (empty($localTaxType))
{
if (empty($localTaxType)) {
accessforbidden('Parameter localTaxType is missing');
exit;
}
@ -281,11 +288,14 @@ $mend = $tmp['mon'];
$total = 0; $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0;
$i = 0; $mcursor = 0;
while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop
{
while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) { // $mcursor is to avoid too large loop
//$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
if ($m == 13) $y++;
if ($m > 12) $m -= 12;
if ($m == 13) {
$y++;
}
if ($m > 12) {
$m -= 12;
}
$mcursor++;
// Get array with details of each line
@ -294,8 +304,7 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
$x_both = array();
//now, from these two arrays, get another array with one rate per line
foreach (array_keys($x_coll) as $my_coll_rate)
{
foreach (array_keys($x_coll) as $my_coll_rate) {
$x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
$x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
$x_both[$my_coll_rate]['coll']['localtax1'] = $x_coll[$my_coll_rate]['localtax1'];
@ -306,7 +315,7 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
$x_both[$my_coll_rate]['paye']['localtax2'] = 0;
$x_both[$my_coll_rate]['coll']['links'] = '';
$x_both[$my_coll_rate]['coll']['detail'] = array();
foreach ($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) {
foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
//$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
//$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
//$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
@ -352,11 +361,9 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
$x_both[$my_paye_rate]['paye']['links'] = '';
$x_both[$my_paye_rate]['paye']['detail'] = array();
foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
{
foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
// ExpenseReport
if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment')
{
if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment') {
//$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
//$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
//$expensereport->type=$x_paye[$my_paye_rate]['type'][$id];
@ -425,14 +432,12 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
$hookmanager->initHooks(array('externalbalance'));
$reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if (!is_array($x_coll) && $coll_listbuy == -1)
{
if (!is_array($x_coll) && $coll_listbuy == -1) {
$langs->load("errors");
print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
break;
}
if (!is_array($x_paye) && $coll_listbuy == -2)
{
if (!is_array($x_paye) && $coll_listbuy == -2) {
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
break;
}
@ -442,17 +447,14 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/localtax/quadri_detail.php?leftmenu=tax_vat&month='.$m.'&year='.$y.'">'.dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y").'</a></td>';
$x_coll_sum = 0;
foreach (array_keys($x_coll) as $rate)
{
foreach (array_keys($x_coll) as $rate) {
$subtot_coll_total_ht = 0;
$subtot_coll_vat = 0;
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields)
{
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
// Payment
$ratiopaymentinvoice = 1;
if ($modetax != 1)
{
if ($modetax != 1) {
// Define type
// We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
$type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
@ -466,8 +468,7 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
}
if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
|| ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
{
|| ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
//print $langs->trans("NA");
} else {
if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
@ -486,17 +487,14 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
print '<td class="nowrap right">'.price(price2num($x_coll_sum, 'MT')).'</td>';
$x_paye_sum = 0;
foreach (array_keys($x_paye) as $rate)
{
foreach (array_keys($x_paye) as $rate) {
$subtot_paye_total_ht = 0;
$subtot_paye_vat = 0;
foreach ($x_both[$rate]['paye']['detail'] as $index => $fields)
{
foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
// Payment
$ratiopaymentinvoice = 1;
if ($modetax != 1)
{
if ($modetax != 1) {
// Define type
// We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
$type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']);
@ -510,8 +508,7 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
}
if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
|| ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
{
|| ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) {
//print $langs->trans("NA");
} else {
if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
@ -541,8 +538,7 @@ while ((($y < $yend) || ($y == $yend && $m <= $mend)) && $mcursor < 1000) // $mc
print "</tr>\n";
$i++; $m++;
if ($i > 2)
{
if ($i > 2) {
print '<tr class="liste_total">';
print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>';
print '<td class="nowrap right">'.price(price2num($subtotalcoll, 'MT')).'</td>';

View File

@ -29,7 +29,9 @@ $langs->load("compta");
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'tax', '', '', 'charges');
$ltt = GETPOST("localTaxType", 'int');
@ -43,7 +45,9 @@ llxHeader();
$localtax_static = new Localtax($db);
$url = DOL_URL_ROOT.'/compta/localtax/card.php?action=create&localTaxType='.$ltt;
if (!empty($socid)) $url .= '&socid='.$socid;
if (!empty($socid)) {
$url .= '&socid='.$socid;
}
$newcardbutton = dolGetButtonTitle($langs->trans('NewLocalTaxPayment', ($ltt + 1)), '', 'fa fa-plus-circle', $url, '', $user->rights->tax->charges->creer);
print load_fiche_titre($langs->transcountry($ltt == 2 ? "LT2Payments" : "LT1Payments", $mysoc->country_code), $newcardbutton, 'title_accountancy');
@ -54,8 +58,7 @@ $sql .= " WHERE f.entity = ".$conf->entity." AND localtaxtype = ".$db->escape($l
$sql .= " ORDER BY datev DESC";
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
$total = 0;
@ -69,8 +72,7 @@ if ($result)
print "<td align=\"right\">".$langs->trans("PayedByThisPayment")."</td>";
print "</tr>\n";
$var = 1;
while ($i < $num)
{
while ($i < $num) {
$obj = $db->fetch_object($result);
print '<tr class="oddeven">';

View File

@ -47,8 +47,7 @@ $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "produ
$local = GETPOST('localTaxType', 'int');
// Date range
$year = GETPOST("year", "int");
if (empty($year))
{
if (empty($year)) {
$year_current = strftime("%Y", dol_now());
$year_start = $year_current;
} else {
@ -58,43 +57,62 @@ if (empty($year))
$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"));
$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"));
// Quarter
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
$q = GETPOST("q", "int");
if (empty($q))
{
if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } else {
if (empty($q)) {
if (GETPOST("month", "int")) {
$date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false);
} else {
$date_start = dol_get_first_day($year_start, empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START, false);
if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) {
$date_end = dol_time_plus_duree($date_start, 3, 'm') - 1;
} elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) {
$date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
} elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) {
$date_end = dol_time_plus_duree($date_start, 1, 'm') - 1;
}
}
} else {
if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
if ($q == 1) {
$date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false);
}
if ($q == 2) {
$date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false);
}
if ($q == 3) {
$date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false);
}
if ($q == 4) {
$date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false);
}
}
}
$min = price2num(GETPOST("min", "alpha"));
if (empty($min)) $min = 0;
if (empty($min)) {
$min = 0;
}
// Define modetax (0 or 1)
// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
//$modetax = $conf->global->TAX_MODE;
$calc = $conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
$modetax = $conf->global->$calc;
if (GETPOSTISSET("modetax")) $modetax = GETPOST("modetax", 'int');
if (empty($modetax)) $modetax = 0;
if (GETPOSTISSET("modetax")) {
$modetax = GETPOST("modetax", 'int');
}
if (empty($modetax)) {
$modetax = 0;
}
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'tax', '', '', 'charges');
if (empty($local))
{
if (empty($local)) {
accessforbidden('Parameter localTaxType is missing');
exit;
}
@ -117,9 +135,10 @@ $paymentexpensereport_static = new PaymentExpenseReport($db);
$morequerystring = '';
$listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
foreach ($listofparams as $param)
{
if (GETPOST($param) != '') $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
foreach ($listofparams as $param) {
if (GETPOST($param) != '') {
$morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param);
}
}
llxHeader('', $langs->trans("LocalTaxReport"), '', '', 0, 0, '', '', $morequerystring);
@ -131,9 +150,15 @@ $fsearch .= '<input type="hidden" name="localTaxType" value="'.$local.'">';
$name = $langs->transcountry($local == 1 ? "LT1ReportByQuarters" : "LT2ReportByQuarters", $mysoc->country_code);
$calcmode = '';
if ($modetax == 0) $calcmode = $langs->trans('OptionVATDefault');
if ($modetax == 1) $calcmode = $langs->trans('OptionVATDebitOption');
if ($modetax == 2) $calcmode = $langs->trans('OptionPaymentForProductAndServices');
if ($modetax == 0) {
$calcmode = $langs->trans('OptionVATDefault');
}
if ($modetax == 1) {
$calcmode = $langs->trans('OptionVATDebitOption');
}
if ($modetax == 2) {
$calcmode = $langs->trans('OptionPaymentForProductAndServices');
}
$calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')</span>';
// Set period
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
@ -164,7 +189,9 @@ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$description.='<br>'.$langs->trans("DepositsAreNotIncluded");
}
*/
if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description .= $langs->trans("ThisIsAnEstimatedValue");
if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
$description .= $langs->trans("ThisIsAnEstimatedValue");
}
// Customers invoices
$elementcust = $langs->trans("CustomersInvoices");
@ -212,28 +239,27 @@ $columns = 4;
$x_coll = tax_by_rate('localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
$x_paye = tax_by_rate('localtax'.$local, $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
if (!is_array($x_coll) || !is_array($x_paye))
{
if (!is_array($x_coll) || !is_array($x_paye)) {
$langs->load("errors");
if ($x_coll == -1)
if ($x_coll == -1) {
print '<tr><td colspan="'.$columns.'">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
elseif ($x_coll == -2)
} elseif ($x_coll == -2) {
print '<tr><td colspan="'.$columns.'">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
else print '<tr><td colspan="'.$columns.'">'.$langs->trans("Error").'</td></tr>';
} else {
print '<tr><td colspan="'.$columns.'">'.$langs->trans("Error").'</td></tr>';
}
} else {
$x_both = array();
//now, from these two arrays, get another array with one rate per line
foreach (array_keys($x_coll) as $my_coll_rate)
{
foreach (array_keys($x_coll) as $my_coll_rate) {
$x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
$x_both[$my_coll_rate]['coll']['localtax'.$local] = $x_coll[$my_coll_rate]['localtax'.$local];
$x_both[$my_coll_rate]['paye']['totalht'] = 0;
$x_both[$my_coll_rate]['paye']['localtax'.$local] = 0;
$x_both[$my_coll_rate]['coll']['links'] = '';
$x_both[$my_coll_rate]['coll']['detail'] = array();
foreach ($x_coll[$my_coll_rate]['facid'] as $id=>$dummy)
{
foreach ($x_coll[$my_coll_rate]['facid'] as $id => $dummy) {
$invoice_customer->id = $x_coll[$my_coll_rate]['facid'][$id];
$invoice_customer->ref = $x_coll[$my_coll_rate]['facnum'][$id];
$invoice_customer->type = $x_coll[$my_coll_rate]['type'][$id];
@ -273,8 +299,7 @@ if (!is_array($x_coll) || !is_array($x_paye))
$x_both[$my_paye_rate]['paye']['links'] = '';
$x_both[$my_paye_rate]['paye']['detail'] = array();
foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
{
foreach ($x_paye[$my_paye_rate]['facid'] as $id => $dummy) {
$invoice_supplier->id = $x_paye[$my_paye_rate]['facid'][$id];
$invoice_supplier->ref = $x_paye[$my_paye_rate]['facnum'][$id];
$invoice_supplier->type = $x_paye[$my_paye_rate]['type'][$id];
@ -312,15 +337,23 @@ if (!is_array($x_coll) || !is_array($x_paye))
$x_paye_ht = 0;
$span = $columns - 1;
if ($modetax != 2) $span += 1;
if ($modetax != 1) $span += 1;
if ($modetax != 2) {
$span += 1;
}
if ($modetax != 1) {
$span += 1;
}
// Customers invoices
print '<tr class="liste_titre">';
print '<td class="left">'.$elementcust.'</td>';
print '<td class="left">'.$productcust.'</td>';
if ($modetax != 2) print '<td class="right">'.$amountcust.'</td>';
if ($modetax != 1) print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
if ($modetax != 2) {
print '<td class="right">'.$amountcust.'</td>';
}
if ($modetax != 1) {
print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
}
print '<td class="right">'.$langs->trans("BI").'</td>';
print '<td class="right">'.$vatcust.'</td>';
print '</tr>';
@ -328,29 +361,29 @@ if (!is_array($x_coll) || !is_array($x_paye))
$LT = 0;
$sameLT = false;
foreach (array_keys($x_coll) as $rate)
{
foreach (array_keys($x_coll) as $rate) {
$subtot_coll_total_ht = 0;
$subtot_coll_vat = 0;
if (is_array($x_both[$rate]['coll']['detail']))
{
if (is_array($x_both[$rate]['coll']['detail'])) {
// VAT Rate
if ($rate != 0) {
print "<tr>";
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
print '</tr>'."\n";
}
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields)
{
if (($local == 1 && $fields['localtax1'] != 0) || ($local == 2 && $fields['localtax2'] != 0))
{
foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) {
if (($local == 1 && $fields['localtax1'] != 0) || ($local == 2 && $fields['localtax2'] != 0)) {
// Define type
$type = ($fields['dtype'] ? $fields['dtype'] : $fields['ptype']);
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
if (!empty($fields['ddate_start'])) $type = 1;
if (!empty($fields['ddate_end'])) $type = 1;
if (!empty($fields['ddate_start'])) {
$type = 1;
}
if (!empty($fields['ddate_end'])) {
$type = 1;
}
print '<tr class="oddeven">';
@ -360,21 +393,28 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Description
print '<td class="left">';
if ($fields['pid'])
{
if ($fields['pid']) {
$product_static->id = $fields['pid'];
$product_static->ref = $fields['pref'];
$product_static->type = $fields['ptype'];
print $product_static->getNomUrl(1);
if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
if (dol_string_nohtmltag($fields['descr'])) {
print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
}
} else {
if ($type) $text = img_object($langs->trans('Service'), 'service');
else $text = img_object($langs->trans('Product'), 'product');
if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg))
{
if ($reg[1] == 'DEPOSIT') $fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
elseif ($reg[1] == 'CREDIT_NOTE') $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote');
else $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]);
if ($type) {
$text = img_object($langs->trans('Service'), 'service');
} else {
$text = img_object($langs->trans('Product'), 'product');
}
if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) {
if ($reg[1] == 'DEPOSIT') {
$fields['descr'] = $langs->transnoentitiesnoconv('Deposit');
} elseif ($reg[1] == 'CREDIT_NOTE') {
$fields['descr'] = $langs->transnoentitiesnoconv('CreditNote');
} else {
$fields['descr'] = $langs->transnoentitiesnoconv($reg[1]);
}
}
print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
@ -384,12 +424,10 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '</td>';
// Total HT
if ($modetax != 2)
{
if ($modetax != 2) {
print '<td class="nowrap right">';
print price($fields['totalht']);
if (price2num($fields['ftotal_ttc']))
{
if (price2num($fields['ftotal_ttc'])) {
$ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
}
print '</td>';
@ -397,21 +435,22 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Payment
$ratiopaymentinvoice = 1;
if ($modetax != 1)
{
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
if ($modetax != 1) {
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
$ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
}
print '<td class="nowrap right">';
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
{
if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
$payment_static->id = $fields['payment_id'];
print $payment_static->getNomUrl(2);
}
if ($type == 0)
{
if ($type == 0) {
print $langs->trans("NotUsedForGoods");
} else {
print price($fields['payment_amount']);
if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice * 100, 2).'%)';
if (isset($fields['payment_amount'])) {
print ' ('.round($ratiopaymentinvoice * 100, 2).'%)';
}
}
print '</td>';
}
@ -419,7 +458,9 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Total collected
print '<td class="nowrap right">';
$temp_ht = $fields['totalht'];
if ($type == 1) $temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
if ($type == 1) {
$temp_ht = $fields['totalht'] * $ratiopaymentinvoice;
}
print price(price2num($temp_ht, 'MT'));
print '</td>';
@ -442,8 +483,7 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '<tr class="liste_total">';
print '<td></td>';
print '<td class="right">'.$langs->trans("Total").':</td>';
if ($modetax != 1)
{
if ($modetax != 1) {
print '<td class="nowrap right">&nbsp;</td>';
print '<td class="right">&nbsp;</td>';
}
@ -452,13 +492,11 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '</tr>';
}
if (count($x_coll) == 0) // Show a total ine if nothing shown
{
if (count($x_coll) == 0) { // Show a total ine if nothing shown
print '<tr class="liste_total">';
print '<td>&nbsp;</td>';
print '<td class="right">'.$langs->trans("Total").':</td>';
if ($modetax == 0)
{
if ($modetax == 0) {
print '<td class="nowrap right">&nbsp;</td>';
print '<td class="right">&nbsp;</td>';
}
@ -477,8 +515,7 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '<tr class="liste_titre">';
print '<td class="left">'.$elementsup.'</td>';
print '<td class="left">'.$productsup.'</td>';
if ($modetax != 1)
{
if ($modetax != 1) {
print '<td class="right">'.$amountsup.'</td>';
print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
}
@ -486,28 +523,28 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '<td class="right">'.$vatsup.'</td>';
print '</tr>'."\n";
foreach (array_keys($x_paye) as $rate)
{
foreach (array_keys($x_paye) as $rate) {
$subtot_paye_total_ht = 0;
$subtot_paye_vat = 0;
if (is_array($x_both[$rate]['paye']['detail']))
{
if (is_array($x_both[$rate]['paye']['detail'])) {
if ($rate != 0) {
print "<tr>";
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
print '</tr>'."\n";
}
foreach ($x_both[$rate]['paye']['detail'] as $index=>$fields)
{
if (($local == 1 && $fields['localtax1'] != 0) || ($local == 2 && $fields['localtax2'] != 0))
{
foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) {
if (($local == 1 && $fields['localtax1'] != 0) || ($local == 2 && $fields['localtax2'] != 0)) {
// Define type
$type = ($fields['dtype'] ? $fields['dtype'] : $fields['ptype']);
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
if (!empty($fields['ddate_start'])) $type = 1;
if (!empty($fields['ddate_end'])) $type = 1;
if (!empty($fields['ddate_start'])) {
$type = 1;
}
if (!empty($fields['ddate_end'])) {
$type = 1;
}
print '<tr class="oddeven">';
@ -517,16 +554,20 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Description
print '<td class="left">';
if ($fields['pid'])
{
if ($fields['pid']) {
$product_static->id = $fields['pid'];
$product_static->ref = $fields['pref'];
$product_static->type = $fields['ptype'];
print $product_static->getNomUrl(1);
if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
if (dol_string_nohtmltag($fields['descr'])) {
print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
}
} else {
if ($type) $text = img_object($langs->trans('Service'), 'service');
else $text = img_object($langs->trans('Product'), 'product');
if ($type) {
$text = img_object($langs->trans('Service'), 'service');
} else {
$text = img_object($langs->trans('Product'), 'product');
}
print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 16);
// Show range
@ -535,12 +576,10 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '</td>';
// Total HT
if ($modetax != 2)
{
if ($modetax != 2) {
print '<td class="nowrap right">';
print price($fields['totalht']);
if (price2num($fields['ftotal_ttc']))
{
if (price2num($fields['ftotal_ttc'])) {
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
$ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']);
//print ' ('.round($ratiolineinvoice*100,2).'%)';
@ -550,17 +589,16 @@ if (!is_array($x_coll) || !is_array($x_paye))
// Payment
$ratiopaymentinvoice = 1;
if ($modetax != 1)
{
if ($modetax != 1) {
print '<td class="nowrap right">';
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
{
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
$ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']);
}
if ($fields['payment_amount'] && $fields['ftotal_ttc']) {
$paymentfourn_static->id = $fields['payment_id'];
print $paymentfourn_static->getNomUrl(2);
}
if ($type == 0)
{
if ($type == 0) {
print $langs->trans("NA");
} else {
print price(price2num($fields['payment_amount'], 'MT'));
@ -596,8 +634,7 @@ if (!is_array($x_coll) || !is_array($x_paye))
print '<tr class="liste_total">';
print '<td>&nbsp;</td>';
print '<td class="right">'.$langs->trans("Total").':</td>';
if ($modetax != 1)
{
if ($modetax != 1) {
print '<td class="nowrap right">&nbsp;</td>';
print '<td class="right">&nbsp;</td>';
}

View File

@ -59,16 +59,14 @@ $multicurrency_amounts = array();
$multicurrency_amountsresttopay = array();
// Security check
if ($user->socid > 0)
{
if ($user->socid > 0) {
$socid = $user->socid;
}
$object = new Facture($db);
// Load object
if ($facid > 0)
{
if ($facid > 0) {
$ret = $object->fetch($facid);
}
@ -84,12 +82,12 @@ $formquestion = array();
$parameters = array('socid'=>$socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook))
{
if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes'))
{
if (empty($reshook)) {
if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes')) {
$error = 0;
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
@ -102,28 +100,27 @@ if (empty($reshook))
// Generate payment array and check if there is payment higher than invoice and payment date before invoice date
$tmpinvoice = new Facture($db);
foreach ($_POST as $key => $value)
{
if (substr($key, 0, 7) == 'amount_' && GETPOST($key) != '')
{
foreach ($_POST as $key => $value) {
if (substr($key, 0, 7) == 'amount_' && GETPOST($key) != '') {
$cursorfacid = substr($key, 7);
$amounts[$cursorfacid] = price2num(GETPOST($key));
$totalpayment = $totalpayment + $amounts[$cursorfacid];
if (!empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
if (!empty($amounts[$cursorfacid])) {
$atleastonepaymentnotnull++;
}
$result = $tmpinvoice->fetch($cursorfacid);
if ($result <= 0) dol_print_error($db);
if ($result <= 0) {
dol_print_error($db);
}
$amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
if ($amounts[$cursorfacid])
{
if ($amounts[$cursorfacid]) {
// Check amount
if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
{
if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) {
$addwarning = 1;
$formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
}
// Check date
if ($datepaye && ($datepaye < $tmpinvoice->date))
{
if ($datepaye && ($datepaye < $tmpinvoice->date)) {
$langs->load("errors");
//$error++;
setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
@ -131,26 +128,26 @@ if (empty($reshook))
}
$formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => $_POST[$key]);
} elseif (substr($key, 0, 21) == 'multicurrency_amount_')
{
} elseif (substr($key, 0, 21) == 'multicurrency_amount_') {
$cursorfacid = substr($key, 21);
$multicurrency_amounts[$cursorfacid] = price2num(GETPOST($key));
$multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid];
if (!empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++;
if (!empty($multicurrency_amounts[$cursorfacid])) {
$atleastonepaymentnotnull++;
}
$result = $tmpinvoice->fetch($cursorfacid);
if ($result <= 0) dol_print_error($db);
if ($result <= 0) {
dol_print_error($db);
}
$multicurrency_amountsresttopay[$cursorfacid] = price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1));
if ($multicurrency_amounts[$cursorfacid])
{
if ($multicurrency_amounts[$cursorfacid]) {
// Check amount
if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid])))
{
if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid]))) {
$addwarning = 1;
$formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
}
// Check date
if ($datepaye && ($datepaye < $tmpinvoice->date))
{
if ($datepaye && ($datepaye < $tmpinvoice->date)) {
$langs->load("errors");
//$error++;
setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
@ -162,37 +159,31 @@ if (empty($reshook))
}
// Check parameters
if (!GETPOST('paiementcode'))
{
if (!GETPOST('paiementcode')) {
setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('PaymentMode')), null, 'errors');
$error++;
}
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
// If bank module is on, account is required to enter a payment
if (GETPOST('accountid') <= 0)
{
if (GETPOST('accountid') <= 0) {
setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors');
$error++;
}
}
if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull))
{
if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) {
setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->trans('PaymentAmount')), null, 'errors');
$error++;
}
if (empty($datepaye))
{
if (empty($datepaye)) {
setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('Date')), null, 'errors');
$error++;
}
// Check if payments in both currency
if ($totalpayment > 0 && $multicurrency_totalpayment > 0)
{
if ($totalpayment > 0 && $multicurrency_totalpayment > 0) {
setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors');
$error++;
}
@ -201,10 +192,8 @@ if (empty($reshook))
/*
* Action add_paiement
*/
if ($action == 'add_paiement')
{
if ($error)
{
if ($action == 'add_paiement') {
if ($error) {
$action = 'create';
}
// The next of this action is displayed at the page's bottom.
@ -213,8 +202,7 @@ if (empty($reshook))
/*
* Action confirm_paiement
*/
if ($action == 'confirm_paiement' && $confirm == 'yes')
{
if ($action == 'confirm_paiement' && $confirm == 'yes') {
$error = 0;
$datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
@ -222,36 +210,32 @@ if (empty($reshook))
$db->begin();
$thirdparty = new Societe($db);
if ($socid > 0) $thirdparty->fetch($socid);
if ($socid > 0) {
$thirdparty->fetch($socid);
}
// Clean parameters amount if payment is for a credit note
foreach ($amounts as $key => $value) // How payment is dispatched
{
foreach ($amounts as $key => $value) { // How payment is dispatched
$tmpinvoice = new Facture($db);
$tmpinvoice->fetch($key);
if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE)
{
if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE) {
$newvalue = price2num($value, 'MT');
$amounts[$key] = - abs($newvalue);
}
}
foreach ($multicurrency_amounts as $key => $value) // How payment is dispatched
{
foreach ($multicurrency_amounts as $key => $value) { // How payment is dispatched
$tmpinvoice = new Facture($db);
$tmpinvoice->fetch($key);
if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE)
{
if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE) {
$newvalue = price2num($value, 'MT');
$multicurrency_amounts[$key] = - abs($newvalue);
}
}
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
// If the bank module is active, an account is required to input a payment
if (GETPOST('accountid', 'int') <= 0)
{
if (GETPOST('accountid', 'int') <= 0) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors');
$error++;
}
@ -266,47 +250,48 @@ if (empty($reshook))
$paiement->num_payment = GETPOST('num_paiement', 'alpha');
$paiement->note_private = GETPOST('comment', 'alpha');
if (!$error)
{
if (!$error) {
// Create payment and update this->multicurrency_amounts if this->amounts filled or
// this->amounts if this->multicurrency_amounts filled.
$paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices') == 'on' ? 1 : 0), $thirdparty); // This include closing invoices and regenerating documents
if ($paiement_id < 0)
{
if ($paiement_id < 0) {
setEventMessages($paiement->error, $paiement->errors, 'errors');
$error++;
}
}
if (!$error)
{
if (!$error) {
$label = '(CustomerInvoicePayment)';
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
if (GETPOST('type') == Facture::TYPE_CREDIT_NOTE) {
$label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
}
$result = $paiement->addPaymentToBank($user, 'payment', $label, GETPOST('accountid'), GETPOST('chqemetteur'), GETPOST('chqbank'));
if ($result < 0)
{
if ($result < 0) {
setEventMessages($paiement->error, $paiement->errors, 'errors');
$error++;
}
}
if (!$error)
{
if (!$error) {
$db->commit();
// If payment dispatching on more than one invoice, we stay on summary page, otherwise jump on invoice card
$invoiceid = 0;
foreach ($paiement->amounts as $key => $amount)
{
foreach ($paiement->amounts as $key => $amount) {
$facid = $key;
if (is_numeric($amount) && $amount <> 0)
{
if ($invoiceid != 0) $invoiceid = -1; // There is more than one invoice payed by this payment
else $invoiceid = $facid;
if (is_numeric($amount) && $amount <> 0) {
if ($invoiceid != 0) {
$invoiceid = -1; // There is more than one invoice payed by this payment
} else {
$invoiceid = $facid;
}
}
}
if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid;
else $loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id;
if ($invoiceid > 0) {
$loc = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$invoiceid;
} else {
$loc = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id;
}
header('Location: '.$loc);
exit;
} else {
@ -327,23 +312,24 @@ llxHeader('', $langs->trans("Payment"));
if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
{
if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement') {
$facture = new Facture($db);
$result = $facture->fetch($facid);
if ($result >= 0)
{
if ($result >= 0) {
$facture->fetch_thirdparty();
$title = '';
if ($facture->type != Facture::TYPE_CREDIT_NOTE) $title .= $langs->trans("EnterPaymentReceivedFromCustomer");
if ($facture->type == Facture::TYPE_CREDIT_NOTE) $title .= $langs->trans("EnterPaymentDueToCustomer");
if ($facture->type != Facture::TYPE_CREDIT_NOTE) {
$title .= $langs->trans("EnterPaymentReceivedFromCustomer");
}
if ($facture->type == Facture::TYPE_CREDIT_NOTE) {
$title .= $langs->trans("EnterPaymentDueToCustomer");
}
print load_fiche_titre($title);
// Initialize data for confirmation (this is used because data can be change during confirmation)
if ($action == 'add_paiement')
{
if ($action == 'add_paiement') {
$i = 0;
$formquestion[$i++] = array('type' => 'hidden', 'name' => 'facid', 'value' => $facture->id);
@ -353,15 +339,15 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
// Invoice with Paypal transaction
// TODO add hook here
if (!empty($conf->paypalplus->enabled) && $conf->global->PAYPAL_ENABLE_TRANSACTION_MANAGEMENT && !empty($facture->ref_ext))
{
if (!empty($conf->global->PAYPAL_BANK_ACCOUNT)) $accountid = $conf->global->PAYPAL_BANK_ACCOUNT;
if (!empty($conf->paypalplus->enabled) && $conf->global->PAYPAL_ENABLE_TRANSACTION_MANAGEMENT && !empty($facture->ref_ext)) {
if (!empty($conf->global->PAYPAL_BANK_ACCOUNT)) {
$accountid = $conf->global->PAYPAL_BANK_ACCOUNT;
}
$paymentnum = $facture->ref_ext;
}
// Add realtime total information
if (!empty($conf->use_javascript_ajax))
{
if (!empty($conf->use_javascript_ajax)) {
print "\n".'<script type="text/javascript" language="javascript">';
print '$(document).ready(function () {
setPaiementCode();
@ -492,10 +478,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
// Bank account
print '<tr>';
if (!empty($conf->banque->enabled))
{
if ($facture->type != 2) print '<td><span class="fieldrequired">'.$langs->trans('AccountToCredit').'</span></td>';
if ($facture->type == 2) print '<td><span class="fieldrequired">'.$langs->trans('AccountToDebit').'</span></td>';
if (!empty($conf->banque->enabled)) {
if ($facture->type != 2) {
print '<td><span class="fieldrequired">'.$langs->trans('AccountToCredit').'</span></td>';
}
if ($facture->type == 2) {
print '<td><span class="fieldrequired">'.$langs->trans('AccountToDebit').'</span></td>';
}
print '<td>';
$form->select_comptes($accountid, 'accountid', 0, '', 2);
print '</td>';
@ -533,8 +522,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
/*
* List of unpaid invoices
*/
* List of unpaid invoices
*/
$sql = 'SELECT f.rowid as facid, f.ref, f.total_ttc, f.multicurrency_code, f.multicurrency_total_ttc, f.type,';
$sql .= ' f.datef as df, f.fk_soc as socid, f.date_lim_reglement as dlr';
@ -551,8 +540,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
$sql .= ') AND f.paye = 0';
$sql .= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled
if ($facture->type != Facture::TYPE_CREDIT_NOTE)
{
if ($facture->type != Facture::TYPE_CREDIT_NOTE) {
$sql .= ' AND type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation
} else {
$sql .= ' AND type = 2'; // If paying back a credit note, we show all credit notes
@ -561,19 +549,23 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$sql .= ' ORDER BY f.datef ASC, f.ref ASC';
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
if ($num > 0)
{
if ($num > 0) {
$arraytitle = $langs->trans('Invoice');
if ($facture->type == 2) $arraytitle = $langs->trans("CreditNotes");
if ($facture->type == 2) {
$arraytitle = $langs->trans("CreditNotes");
}
$alreadypayedlabel = $langs->trans('Received');
$multicurrencyalreadypayedlabel = $langs->trans('MulticurrencyReceived');
if ($facture->type == 2) { $alreadypayedlabel = $langs->trans("PaidBack"); $multicurrencyalreadypayedlabel = $langs->trans("MulticurrencyPaidBack"); }
if ($facture->type == 2) {
$alreadypayedlabel = $langs->trans("PaidBack"); $multicurrencyalreadypayedlabel = $langs->trans("MulticurrencyPaidBack");
}
$remaindertopay = $langs->trans('RemainderToTake');
$multicurrencyremaindertopay = $langs->trans('MulticurrencyRemainderToTake');
if ($facture->type == 2) { $remaindertopay = $langs->trans("RemainderToPayBack"); $multicurrencyremaindertopay = $langs->trans("MulticurrencyRemainderToPayBack"); }
if ($facture->type == 2) {
$remaindertopay = $langs->trans("RemainderToPayBack"); $multicurrencyremaindertopay = $langs->trans("MulticurrencyRemainderToPayBack");
}
$i = 0;
//print '<tr><td colspan="3">';
@ -609,12 +601,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$totalrecucreditnote = 0;
$totalrecudeposits = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $db->fetch_object($resql);
$sign = 1;
if ($facture->type == Facture::TYPE_CREDIT_NOTE) $sign = -1;
if ($facture->type == Facture::TYPE_CREDIT_NOTE) {
$sign = -1;
}
$soc = new Societe($db);
$soc->fetch($objp->socid);
@ -641,20 +634,20 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '<td class="nowraponall">';
print $invoice->getNomUrl(1, '');
if ($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' ';
if ($objp->socid != $facture->thirdparty->id) {
print ' - '.$soc->getNomUrl(1).' ';
}
print "</td>\n";
// Date
print '<td class="center">'.dol_print_date($db->jdate($objp->df), 'day')."</td>\n";
print '<td class="center">'.dol_print_date($db->jdate($objp->df), 'day')."</td>\n";
// Due date
if ($objp->dlr > 0)
{
if ($objp->dlr > 0) {
print '<td class="nowraponall center">';
print dol_print_date($db->jdate($objp->dlr), 'day');
if ($invoice->hasDelay())
{
if ($invoice->hasDelay()) {
print img_warning($langs->trans('Late'));
}
@ -664,28 +657,36 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
// Currency
if (!empty($conf->multicurrency->enabled)) print '<td class="center">'.$objp->multicurrency_code."</td>\n";
if (!empty($conf->multicurrency->enabled)) {
print '<td class="center">'.$objp->multicurrency_code."</td>\n";
}
// Multicurrency Price
if (!empty($conf->multicurrency->enabled))
{
if (!empty($conf->multicurrency->enabled)) {
print '<td class="right">';
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $objp->multicurrency_total_ttc);
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
print price($sign * $objp->multicurrency_total_ttc);
}
print '</td>';
// Multicurrency Price
print '<td class="right">';
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
{
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
print price($sign * $multicurrency_payment);
if ($multicurrency_creditnotes) print '+'.price($multicurrency_creditnotes);
if ($multicurrency_deposits) print '+'.price($multicurrency_deposits);
if ($multicurrency_creditnotes) {
print '+'.price($multicurrency_creditnotes);
}
if ($multicurrency_deposits) {
print '+'.price($multicurrency_deposits);
}
}
print '</td>';
// Multicurrency remain to pay
print '<td class="right">';
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $multicurrency_remaintopay);
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
print price($sign * $multicurrency_remaintopay);
}
print '</td>';
print '<td class="right nowraponall">';
@ -694,14 +695,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$namef = 'multicurrency_amount_'.$objp->facid;
$nameRemain = 'multicurrency_remain_'.$objp->facid;
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
{
if ($action != 'add_paiement')
{
if (!empty($conf->use_javascript_ajax))
if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) {
if ($action != 'add_paiement') {
if (!empty($conf->use_javascript_ajax)) {
print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
print '<input type="text" class="maxwidth75 multicurrency_amount" name="'.$namef.'" value="'.$_POST[$namef].'">';
print '<input type="hidden" class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
}
print '<input type="text" class="maxwidth75 multicurrency_amount" name="'.$namef.'" value="'.$_POST[$namef].'">';
print '<input type="hidden" class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
} else {
print '<input type="text" class="maxwidth75" name="'.$namef.'_disabled" value="'.$_POST[$namef].'" disabled>';
print '<input type="hidden" name="'.$namef.'" value="'.$_POST[$namef].'">';
@ -715,8 +715,12 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
// Received + already paid
print '<td class="right">'.price($sign * $paiement);
if ($creditnotes) print '<span class="opacitymedium">+'.price($creditnotes).'</span>';
if ($deposits) print '<span class="opacitymedium">+'.price($deposits).'</span>';
if ($creditnotes) {
print '<span class="opacitymedium">+'.price($creditnotes).'</span>';
}
if ($deposits) {
print '<span class="opacitymedium">+'.price($deposits).'</span>';
}
print '</td>';
// Remain to take or to pay back
@ -730,10 +734,10 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$namef = 'amount_'.$objp->facid;
$nameRemain = 'remain_'.$objp->facid;
if ($action != 'add_paiement')
{
if (!empty($conf->use_javascript_ajax))
if ($action != 'add_paiement') {
if (!empty($conf->use_javascript_ajax)) {
print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
}
print '<input type="text" class="maxwidth75 amount" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
print '<input type="hidden" class="remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
} else {
@ -749,8 +753,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '<td align="center" width="16">';
//print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."<br>";
if ($amounts[$invoice->id] && (abs($amounts[$invoice->id]) > abs($amountsresttopay[$invoice->id]))
|| $multicurrency_amounts[$invoice->id] && (abs($multicurrency_amounts[$invoice->id]) > abs($multicurrency_amountsresttopay[$invoice->id])))
{
|| $multicurrency_amounts[$invoice->id] && (abs($multicurrency_amounts[$invoice->id]) > abs($multicurrency_amountsresttopay[$invoice->id]))) {
print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay"));
}
print '</td>';
@ -765,8 +768,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$i++;
}
if ($i > 1)
{
if ($i > 1) {
// Print total
print '<tr class="liste_total">';
print '<td colspan="3" class="left">'.$langs->trans('TotalTTC').'</td>';
@ -779,8 +781,12 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
}
print '<td class="right"><b>'.price($sign * $total_ttc).'</b></td>';
print '<td class="right"><b>'.price($sign * $totalrecu);
if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
if ($totalrecucreditnote) {
print '+'.price($totalrecucreditnote);
}
if ($totalrecudeposits) {
print '+'.price($totalrecudeposits);
}
print '</b></td>';
print '<td class="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).'</b></td>';
print '<td class="right" id="result" style="font-weight: bold;"></td>'; // Autofilled
@ -797,37 +803,39 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
// Save button
if ($action != 'add_paiement')
{
if ($action != 'add_paiement') {
$checkboxlabel = $langs->trans("ClosePaidInvoicesAutomatically");
if ($facture->type == Facture::TYPE_CREDIT_NOTE) $checkboxlabel = $langs->trans("ClosePaidCreditNotesAutomatically");
if ($facture->type == Facture::TYPE_CREDIT_NOTE) {
$checkboxlabel = $langs->trans("ClosePaidCreditNotesAutomatically");
}
$buttontitle = $langs->trans('ToMakePayment');
if ($facture->type == Facture::TYPE_CREDIT_NOTE) $buttontitle = $langs->trans('ToMakePaymentBack');
if ($facture->type == Facture::TYPE_CREDIT_NOTE) {
$buttontitle = $langs->trans('ToMakePaymentBack');
}
print '<br><div class="center">';
print '<input type="checkbox" checked name="closepaidinvoices"> '.$checkboxlabel;
/*if (! empty($conf->prelevement->enabled))
{
$langs->load("withdrawals");
if (! empty($conf->global->WITHDRAW_DISABLE_AUTOCREATE_ONPAYMENTS)) print '<br>'.$langs->trans("IfInvoiceNeedOnWithdrawPaymentWontBeClosed");
}*/
{
$langs->load("withdrawals");
if (! empty($conf->global->WITHDRAW_DISABLE_AUTOCREATE_ONPAYMENTS)) print '<br>'.$langs->trans("IfInvoiceNeedOnWithdrawPaymentWontBeClosed");
}*/
print '<br><input type="submit" class="button" value="'.dol_escape_htmltag($buttontitle).'"><br><br>';
print '</div>';
}
// Form to confirm payment
if ($action == 'add_paiement')
{
if ($action == 'add_paiement') {
$preselectedchoice = $addwarning ? 'no' : 'yes';
print '<br>';
if (!empty($totalpayment)) $text = $langs->trans('ConfirmCustomerPayment', $totalpayment, $langs->trans("Currency".$conf->currency));
if (!empty($multicurrency_totalpayment))
{
if (!empty($totalpayment)) {
$text = $langs->trans('ConfirmCustomerPayment', $totalpayment, $langs->trans("Currency".$conf->currency));
}
if (!empty($multicurrency_totalpayment)) {
$text .= '<br>'.$langs->trans('ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->trans("paymentInInvoiceCurrency"));
}
if (GETPOST('closepaidinvoices'))
{
if (GETPOST('closepaidinvoices')) {
$text .= '<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
print '<input type="hidden" name="closepaidinvoices" value="'.GETPOST('closepaidinvoices').'">';
}
@ -842,14 +850,19 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
/**
* Show list of payments
*/
if (!GETPOST('action', 'aZ09'))
{
if (empty($page) || $page == -1) $page = 0;
if (!GETPOST('action', 'aZ09')) {
if (empty($page) || $page == -1) {
$page = 0;
}
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$offset = $limit * $page;
if (!$sortorder) $sortorder = 'DESC';
if (!$sortfield) $sortfield = 'p.datep';
if (!$sortorder) {
$sortorder = 'DESC';
}
if (!$sortfield) {
$sortfield = 'p.datep';
}
$sql = 'SELECT p.datep as dp, p.amount, f.total_ttc as fa_amount, f.ref';
$sql .= ', f.rowid as facid, c.libelle as paiement_type, p.num_paiement as num_payment';
@ -857,8 +870,7 @@ if (!GETPOST('action', 'aZ09'))
$sql .= ', '.MAIN_DB_PREFIX.'facture as f';
$sql .= ' WHERE p.fk_facture = f.rowid';
$sql .= ' AND f.entity IN ('.getEntity('invoice').')';
if ($socid)
{
if ($socid) {
$sql .= ' AND f.fk_soc = '.$socid;
}
@ -866,8 +878,7 @@ if (!GETPOST('action', 'aZ09'))
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -881,8 +892,7 @@ if (!GETPOST('action', 'aZ09'))
print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
print "</tr>\n";
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($resql);
print '<tr class="oddeven">';

View File

@ -32,7 +32,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
if (!empty($conf->banque->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
// Load translation files required by the page
$langs->loadLangs(array('bills', 'banks', 'companies'));
@ -53,7 +55,9 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ
$result = restrictedArea($user, $object->element, $object->id, 'paiement', '');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
// Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
// It should be enough because all payments are done on invoices of the same thirdparty.
if ($socid && $socid != $object->thirdparty->id) {
@ -65,13 +69,11 @@ if ($socid && $socid != $object->thirdparty->id) {
* Actions
*/
if ($action == 'setnote' && $user->rights->facture->paiement)
{
if ($action == 'setnote' && $user->rights->facture->paiement) {
$db->begin();
$result = $object->update_note(GETPOST('note', 'restricthtml'));
if ($result > 0)
{
if ($result > 0) {
$db->commit();
$action = '';
} else {
@ -80,17 +82,14 @@ if ($action == 'setnote' && $user->rights->facture->paiement)
}
}
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->paiement)
{
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->paiement) {
$db->begin();
$result = $object->delete();
if ($result > 0)
{
if ($result > 0) {
$db->commit();
if ($backtopage)
{
if ($backtopage) {
header("Location: ".$backtopage);
exit;
} else {
@ -104,24 +103,20 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->
}
}
if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->facture->paiement)
{
if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->facture->paiement) {
$db->begin();
if ($object->validate($user) > 0)
{
if ($object->validate($user) > 0) {
$db->commit();
// Loop on each invoice linked to this payment to rebuild PDF
$factures = array();
foreach ($factures as $id)
{
foreach ($factures as $id) {
$fac = new Facture($db);
$fac->fetch($id);
$outputlangs = $langs;
if (!empty($_REQUEST['lang_id']))
{
if (!empty($_REQUEST['lang_id'])) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
@ -139,23 +134,19 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->facture
}
}
if ($action == 'setnum_paiement' && !empty($_POST['num_paiement']))
{
if ($action == 'setnum_paiement' && !empty($_POST['num_paiement'])) {
$res = $object->update_num($_POST['num_paiement']);
if ($res === 0)
{
if ($res === 0) {
setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
} else {
setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
}
}
if ($action == 'setdatep' && !empty($_POST['datepday']))
{
if ($action == 'setdatep' && !empty($_POST['datepday'])) {
$datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'));
$res = $object->update_date($datepaye);
if ($res === 0)
{
if ($res === 0) {
setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
} else {
setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
@ -172,8 +163,7 @@ llxHeader('', $langs->trans("Payment"));
$thirdpartystatic = new Societe($db);
$result = $object->fetch($id, $ref);
if ($result <= 0)
{
if ($result <= 0) {
dol_print_error($db, 'Payement '.$id.' not found in database');
exit;
}
@ -185,14 +175,12 @@ $head = payment_prepare_head($object);
print dol_get_fiche_head($head, 'payment', $langs->trans("PaymentCustomerInvoice"), -1, 'payment');
// Confirmation of payment delete
if ($action == 'delete')
{
if ($action == 'delete') {
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
}
// Confirmation of payment validation
if ($action == 'valide')
{
if ($action == 'valide') {
$facid = $_GET['facid'];
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_validate', '', 0, 2);
}
@ -223,15 +211,12 @@ print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, '',
$disable_delete = 0;
// Bank account
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
$bankline = new AccountLine($db);
if ($object->fk_account > 0)
{
if ($object->fk_account > 0) {
$bankline->fetch($object->bank_line);
if ($bankline->rappro)
{
if ($bankline->rappro) {
$disable_delete = 1;
$title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
}
@ -268,8 +253,7 @@ print '</td></tr>';
*/
// Bank account
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
if ($object->fk_account > 0) {
if ($object->type_code == 'CHQ' && $bankline->fk_bordereau > 0) {
dol_include_once('/compta/paiement/cheque/class/remisecheque.class.php');
@ -321,8 +305,7 @@ $sql .= ' AND f.fk_soc = s.rowid';
$sql .= ' AND f.entity IN ('.getEntity('invoice').')';
$sql .= ' AND pf.fk_paiement = '.$object->id;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -338,17 +321,17 @@ if ($resql)
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Bill').'</td>';
print '<td>'.$langs->trans('Company').'</td>';
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) print '<td>'.$langs->trans('Entity').'</td>';
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)) {
print '<td>'.$langs->trans('Entity').'</td>';
}
print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
print '<td class="right">'.$langs->trans('RemainderToPay').'</td>';
print '<td class="right">'.$langs->trans('Status').'</td>';
print "</tr>\n";
if ($num > 0)
{
while ($i < $num)
{
if ($num > 0) {
while ($i < $num) {
$objp = $db->fetch_object($resql);
$thirdpartystatic->fetch($objp->socid);
@ -394,8 +377,7 @@ if ($resql)
print '<td class="right">'.$invoice->getLibStatut(5, $alreadypayed).'</td>';
print "</tr>\n";
if ($objp->paye == 1) // If at least one invoice is paid, disable delete
{
if ($objp->paye == 1) { // If at least one invoice is paid, disable delete
$disable_delete = 1;
$title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
}
@ -421,23 +403,17 @@ if ($resql)
print '<div class="tabsAction">';
if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
{
if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '')
{
if ($user->rights->facture->paiement)
{
if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '') {
if ($user->rights->facture->paiement) {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
}
}
}
if ($user->socid == 0 && $action == '')
{
if ($user->rights->facture->paiement)
{
if (!$disable_delete)
{
if ($user->socid == 0 && $action == '') {
if ($user->rights->facture->paiement) {
if (!$disable_delete) {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$title_button.'">'.$langs->trans('Delete').'</a>';

View File

@ -43,15 +43,23 @@ $confirm = GETPOST('confirm', 'alpha');
// Security check
$fieldname = (!empty($ref) ? 'ref' : 'rowid');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'cheque', $id, 'bordereau_cheque', '', 'fk_user_author', $fieldname);
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (!$sortorder) $sortorder = "ASC";
if (!$sortfield) $sortfield = "b.dateo,b.rowid";
if (empty($page) || $page == -1) { $page = 0; }
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "b.dateo,b.rowid";
}
if (empty($page) || $page == -1) {
$page = 0;
}
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$offset = $limit * $page;
@ -66,17 +74,14 @@ $object = new RemiseCheque($db);
* Actions
*/
if ($action == 'setdate' && $user->rights->banque->cheque)
{
if ($action == 'setdate' && $user->rights->banque->cheque) {
$result = $object->fetch(GETPOST('id', 'int'));
if ($result > 0)
{
if ($result > 0) {
//print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];
$date = dol_mktime(0, 0, 0, $_POST['datecreate_month'], $_POST['datecreate_day'], $_POST['datecreate_year']);
$result = $object->set_date($user, $date);
if ($result < 0)
{
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
} else {
@ -84,16 +89,13 @@ if ($action == 'setdate' && $user->rights->banque->cheque)
}
}
if ($action == 'setrefext' && $user->rights->banque->cheque)
{
if ($action == 'setrefext' && $user->rights->banque->cheque) {
$result = $object->fetch(GETPOST('id', 'int'));
if ($result > 0)
{
if ($result > 0) {
$ref_ext = GETPOST('ref_ext');
$result = $object->setValueFrom('ref_ext', $ref_ext, '', null, 'text', '', $user, 'CHECKDEPOSIT_MODIFY');
if ($result < 0)
{
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
} else {
@ -101,16 +103,13 @@ if ($action == 'setrefext' && $user->rights->banque->cheque)
}
}
if ($action == 'setref' && $user->rights->banque->cheque)
{
if ($action == 'setref' && $user->rights->banque->cheque) {
$result = $object->fetch(GETPOST('id', 'int'));
if ($result > 0)
{
if ($result > 0) {
$ref = GETPOST('ref');
$result = $object->set_number($user, $ref);
if ($result < 0)
{
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
} else {
@ -118,30 +117,27 @@ if ($action == 'setref' && $user->rights->banque->cheque)
}
}
if ($action == 'create' && $_POST["accountid"] > 0 && $user->rights->banque->cheque)
{
if (is_array($_POST['toRemise']))
{
if ($action == 'create' && $_POST["accountid"] > 0 && $user->rights->banque->cheque) {
if (is_array($_POST['toRemise'])) {
$result = $object->create($user, $_POST["accountid"], 0, $_POST['toRemise']);
if ($result > 0)
{
if ($object->statut == 1) // If statut is validated, we build doc
{
if ($result > 0) {
if ($object->statut == 1) { // If statut is validated, we build doc
$object->fetch($object->id); // To force to reload all properties in correct property name
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) $newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) {
$newlang = $_REQUEST['lang_id'];
}
//if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (!empty($newlang))
{
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
$result = $object->generatePdf($_POST["model"], $outputlangs);
}
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
exit;
} else {
setEventMessages($object->error, $object->errors, 'errors');
@ -152,12 +148,10 @@ if ($action == 'create' && $_POST["accountid"] > 0 && $user->rights->banque->che
}
}
if ($action == 'remove' && $id > 0 && GETPOST("lineid", 'int') > 0 && $user->rights->banque->cheque)
{
if ($action == 'remove' && $id > 0 && GETPOST("lineid", 'int') > 0 && $user->rights->banque->cheque) {
$object->id = $id;
$result = $object->removeCheck(GETPOST("lineid", "int"));
if ($result === 0)
{
if ($result === 0) {
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
exit;
} else {
@ -165,12 +159,10 @@ if ($action == 'remove' && $id > 0 && GETPOST("lineid", 'int') > 0 && $user->rig
}
}
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->cheque)
{
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->cheque) {
$object->id = $id;
$result = $object->delete();
if ($result == 0)
{
if ($result == 0) {
header("Location: index.php");
exit;
} else {
@ -178,19 +170,18 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->c
}
}
if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->banque->cheque)
{
if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->banque->cheque) {
$result = $object->fetch($id);
$result = $object->validate($user);
if ($result >= 0)
{
if ($result >= 0) {
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) $newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) {
$newlang = $_REQUEST['lang_id'];
}
//if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (!empty($newlang))
{
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
@ -203,15 +194,13 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->banque-
}
}
if ($action == 'confirm_reject_check' && $confirm == 'yes' && $user->rights->banque->cheque)
{
if ($action == 'confirm_reject_check' && $confirm == 'yes' && $user->rights->banque->cheque) {
$reject_date = dol_mktime(0, 0, 0, GETPOST('rejectdate_month'), GETPOST('rejectdate_day'), GETPOST('rejectdate_year'));
$rejected_check = GETPOST('bankid', 'int');
$object->fetch($id);
$paiement_id = $object->rejectCheck($rejected_check, $reject_date);
if ($paiement_id > 0)
{
if ($paiement_id > 0) {
setEventMessages($langs->trans("CheckRejectedAndInvoicesReopened"), null, 'mesgs');
//header("Location: ".DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id);
//exit;
@ -222,8 +211,7 @@ if ($action == 'confirm_reject_check' && $confirm == 'yes' && $user->rights->ban
}
}
if ($action == 'builddoc' && $user->rights->banque->cheque)
{
if ($action == 'builddoc' && $user->rights->banque->cheque) {
$result = $object->fetch($id);
// Save last template used to generate document
@ -231,16 +219,16 @@ if ($action == 'builddoc' && $user->rights->banque->cheque)
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) $newlang = $_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) {
$newlang = $_REQUEST['lang_id'];
}
//if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (!empty($newlang))
{
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
$result = $object->generatePdf($_POST["model"], $outputlangs);
if ($result <= 0)
{
if ($result <= 0) {
dol_print_error($db, $object->error);
exit;
} else {
@ -248,18 +236,19 @@ if ($action == 'builddoc' && $user->rights->banque->cheque)
exit;
}
} // Remove file in doc form
elseif ($action == 'remove_file' && $user->rights->banque->cheque)
{
if ($object->fetch($id) > 0)
{
elseif ($action == 'remove_file' && $user->rights->banque->cheque) {
if ($object->fetch($id) > 0) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$langs->load("other");
$file = $dir.get_exdir($object->ref, 0, 1, 0, $object, 'cheque').GETPOST('file');
$ret = dol_delete_file($file, 0, 0, 0, $object);
if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
if ($ret) {
setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
} else {
setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
}
}
}
@ -268,8 +257,7 @@ elseif ($action == 'remove_file' && $user->rights->banque->cheque)
* View
*/
if (GETPOST('removefilter'))
{
if (GETPOST('removefilter')) {
$filterdate = '';
$filteraccountid = 0;
}
@ -282,8 +270,7 @@ $form = new Form($db);
$formfile = new FormFile($db);
if ($action == 'new')
{
if ($action == 'new') {
$head = array();
$h = 0;
$head[$h][0] = $_SERVER["PHP_SELF"].'?action=new';
@ -294,8 +281,7 @@ if ($action == 'new')
print load_fiche_titre($langs->trans("Cheques"), '', 'bank_account');
} else {
$result = $object->fetch($id, $ref);
if ($result < 0)
{
if ($result < 0) {
dol_print_error($db, $object->error);
exit;
}
@ -314,24 +300,21 @@ if ($action == 'new')
/*
* Confirmation of slip's delete
*/
if ($action == 'delete')
{
if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("DeleteCheckReceipt"), $langs->trans("ConfirmDeleteCheckReceipt"), 'confirm_delete', '', '', 1);
}
/*
* Confirmation of slip's validation
*/
if ($action == 'valide')
{
if ($action == 'valide') {
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("ValidateCheckReceipt"), $langs->trans("ConfirmValidateCheckReceipt"), 'confirm_validate', '', '', 1);
}
/*
* Confirm check rejection
*/
if ($action == 'reject_check')
{
if ($action == 'reject_check') {
$formquestion = array(
array('type' => 'hidden', 'name' => 'bankid', 'value' => GETPOST('lineid', 'int')),
array('type' => 'date', 'name' => 'rejectdate_', 'label' => $langs->trans("RejectCheckDate"), 'value' => dol_now())
@ -342,8 +325,7 @@ if ($action == 'new')
$accounts = array();
if ($action == 'new')
{
if ($action == 'new') {
$paymentstatic = new Paiement($db);
$accountlinestatic = new AccountLine($db);
@ -374,8 +356,7 @@ if ($action == 'new')
print '<div class="center">';
print '<input type="submit" class="button" name="filter" value="'.dol_escape_htmltag($langs->trans("ToFilter")).'">';
if ($filterdate || $filteraccountid > 0)
{
if ($filterdate || $filteraccountid > 0) {
print ' &nbsp; ';
print '<input type="submit" class="button" name="removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
}
@ -393,16 +374,18 @@ if ($action == 'new')
$sql .= " AND ba.entity IN (".getEntity('bank_account').")";
$sql .= " AND b.fk_bordereau = 0";
$sql .= " AND b.amount > 0";
if ($filterdate) $sql .= " AND b.dateo = '".$db->idate($filterdate)."'";
if ($filteraccountid > 0) $sql .= " AND ba.rowid = ".((int) $filteraccountid);
if ($filterdate) {
$sql .= " AND b.dateo = '".$db->idate($filterdate)."'";
}
if ($filteraccountid > 0) {
$sql .= " AND ba.rowid = ".((int) $filteraccountid);
}
$sql .= $db->order("b.dateo,b.rowid", "ASC");
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$i = 0;
while ($obj = $db->fetch_object($resql))
{
while ($obj = $db->fetch_object($resql)) {
$accounts[$obj->bid] = $obj->label;
$lines[$obj->bid][$i]["date"] = $db->jdate($obj->date);
$lines[$obj->bid][$i]["amount"] = $obj->amount;
@ -415,14 +398,12 @@ if ($action == 'new')
$i++;
}
if ($i == 0)
{
if ($i == 0) {
print '<div class="opacitymedium">'.$langs->trans("NoWaitingChecks").'</div><br>';
}
}
foreach ($accounts as $bid => $account_label)
{
foreach ($accounts as $bid => $account_label) {
print '
<script language="javascript" type="text/javascript">
jQuery(document).ready(function()
@ -458,14 +439,14 @@ if ($action == 'new')
print '<td class="center">'.$langs->trans("Payment")."</td>\n";
print '<td class="center">'.$langs->trans("LineRecord")."</td>\n";
print '<td class="center">'.$langs->trans("Select")."<br>";
if ($conf->use_javascript_ajax) print '<a href="#" id="checkall_'.$bid.'">'.$langs->trans("All").'</a> / <a href="#" id="checknone_'.$bid.'">'.$langs->trans("None").'</a>';
if ($conf->use_javascript_ajax) {
print '<a href="#" id="checkall_'.$bid.'">'.$langs->trans("All").'</a> / <a href="#" id="checknone_'.$bid.'">'.$langs->trans("None").'</a>';
}
print '</td>';
print "</tr>\n";
if (count($lines[$bid]))
{
foreach ($lines[$bid] as $lid => $value)
{
if (count($lines[$bid])) {
foreach ($lines[$bid] as $lid => $value) {
//$account_id = $bid; FIXME not used
// FIXME $accounts[$bid] is a label !
@ -484,8 +465,7 @@ if ($action == 'new')
print '<td class="center">';
$paymentstatic->id = $value["paymentid"];
$paymentstatic->ref = $value["paymentref"];
if ($paymentstatic->id)
{
if ($paymentstatic->id) {
print $paymentstatic->getNomUrl(1);
} else {
print '&nbsp;';
@ -494,8 +474,7 @@ if ($action == 'new')
// Link to bank transaction
print '<td class="center">';
$accountlinestatic->rowid = $value["id"];
if ($accountlinestatic->rowid)
{
if ($accountlinestatic->rowid) {
print $accountlinestatic->getNomUrl(1);
} else {
print '&nbsp;';
@ -514,8 +493,7 @@ if ($action == 'new')
print '</div>';
print '<div class="tabsAction">';
if ($user->rights->banque->cheque)
{
if ($user->rights->banque->cheque) {
print '<input type="submit" class="button" value="'.$langs->trans('NewCheckDepositOn', $account_label).'">';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('NewCheckDepositOn', $account_label).'</a>';
@ -546,11 +524,12 @@ if ($action == 'new')
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Date');
print '</td>';
if ($action != 'editdate') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
if ($action != 'editdate') {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td colspan="2">';
if ($action == 'editdate')
{
if ($action == 'editdate') {
print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setdate">';
@ -569,24 +548,24 @@ if ($action == 'new')
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('RefExt');
print '</td>';
if ($action != 'editrefext') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrefext&amp;id='.$object->id.'">'.img_edit($langs->trans('SetRefExt'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($action == 'editrefext')
{
print '<form name="setrefext" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setrefext">';
print '<input type="text" name="ref_ext" value="'.$object->ref_ext.'">';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
}
else
{
print $object->ref_ext;
}
print $langs->trans('RefExt');
print '</td>';
if ($action != 'editrefext') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrefext&amp;id='.$object->id.'">'.img_edit($langs->trans('SetRefExt'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($action == 'editrefext')
{
print '<form name="setrefext" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setrefext">';
print '<input type="text" name="ref_ext" value="'.$object->ref_ext.'">';
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
}
else
{
print $object->ref_ext;
}
print '</td>';
print '</tr>';
@ -627,8 +606,7 @@ if ($action == 'new')
$sql .= $db->order($sortfield, $sortorder);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
print '<div class="div-table-responsive">';
@ -649,10 +627,8 @@ if ($action == 'new')
print "</tr>\n";
$i = 1;
if ($num > 0)
{
while ($objp = $db->fetch_object($resql))
{
if ($num > 0) {
while ($objp = $db->fetch_object($resql)) {
print '<tr class="oddeven">';
print '<td class="center">'.$i.'</td>';
print '<td class="center">'.dol_print_date($db->jdate($objp->date), 'day').'</td>'; // Operation date
@ -681,16 +657,13 @@ if ($action == 'new')
print '</td>';
// Action button
print '<td class="right">';
if ($object->statut == 0)
{
if ($object->statut == 0) {
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=remove&amp;lineid='.$objp->rowid.'">'.img_delete().'</a>';
}
if ($object->statut == 1 && $objp->statut != 2)
{
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reject_check&amp;lineid='.$objp->rowid.'">'.img_picto($langs->trans("RejectCheck"), 'disable').'</a>';
}
if ($objp->statut == 2)
{
if ($object->statut == 1 && $objp->statut != 2) {
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reject_check&amp;lineid='.$objp->rowid.'">'.img_picto($langs->trans("RejectCheck"), 'disable').'</a>';
}
if ($objp->statut == 2) {
print ' &nbsp; '.img_picto($langs->trans('CheckRejected'), 'statut8').'</a>';
}
print '</td>';
@ -731,23 +704,19 @@ if ($action == 'new')
print '<div class="tabsAction">';
if ($user->socid == 0 && !empty($object->id) && $object->statut == 0 && $user->rights->banque->cheque)
{
if ($user->socid == 0 && !empty($object->id) && $object->statut == 0 && $user->rights->banque->cheque) {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valide&amp;token='.newToken().'&amp;sortfield='.$sortfield.'&amp;sortorder='.$sortorder.'">'.$langs->trans('Validate').'</a>';
}
if ($user->socid == 0 && !empty($object->id) && $user->rights->banque->cheque)
{
if ($user->socid == 0 && !empty($object->id) && $user->rights->banque->cheque) {
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'&amp;sortfield='.$sortfield.'&amp;sortorder='.$sortorder.'">'.$langs->trans('Delete').'</a>';
}
print '</div>';
if ($action != 'new')
{
if ($object->statut == 1)
{
if ($action != 'new') {
if ($object->statut == 1) {
$filename = dol_sanitizeFileName($object->ref);
$filedir = $dir.get_exdir($object->ref, 0, 1, 0, $object, 'checkdeposits');
$urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;

View File

@ -98,15 +98,17 @@ class RemiseCheque extends CommonObject
$sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON bc.fk_bank_account = ba.rowid";
$sql .= " WHERE bc.entity = ".$conf->entity;
if ($id) $sql .= " AND bc.rowid = ".((int) $id);
if ($ref) $sql .= " AND bc.ref = '".$this->db->escape($ref)."'";
if ($id) {
$sql .= " AND bc.rowid = ".((int) $id);
}
if ($ref) {
$sql .= " AND bc.ref = '".$this->db->escape($ref)."'";
}
dol_syslog("RemiseCheque::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($obj = $this->db->fetch_object($resql))
{
if ($resql) {
if ($obj = $this->db->fetch_object($resql)) {
$this->id = $obj->rowid;
$this->amount = $obj->amount;
$this->date_bordereau = $this->db->jdate($obj->date_bordereau);
@ -117,8 +119,7 @@ class RemiseCheque extends CommonObject
$this->statut = $obj->statut;
$this->ref_ext = $obj->ref_ext;
if ($this->statut == 0)
{
if ($this->statut == 0) {
$this->ref = "(PROV".$this->id.")";
} else {
$this->ref = $obj->ref;
@ -180,31 +181,26 @@ class RemiseCheque extends CommonObject
$sql .= ")";
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque");
if ($this->id == 0)
{
if ($this->id == 0) {
$this->errno = -1024;
dol_syslog("Remisecheque::Create Error read id ".$this->errno, LOG_ERR);
}
if ($this->id > 0 && $this->errno == 0)
{
if ($this->id > 0 && $this->errno == 0) {
$sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
$sql .= " SET ref='(PROV".$this->id.")'";
$sql .= " WHERE rowid=".$this->id."";
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$this->errno = -1025;
dol_syslog("RemiseCheque::Create Error update ".$this->errno, LOG_ERR);
}
}
if ($this->id > 0 && $this->errno == 0)
{
if ($this->id > 0 && $this->errno == 0) {
$lines = array();
$sql = "SELECT b.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
@ -212,14 +208,14 @@ class RemiseCheque extends CommonObject
$sql .= " AND b.amount > 0";
$sql .= " AND b.fk_bordereau = 0";
$sql .= " AND b.fk_account = ".((int) $account_id);
if ($limit) $sql .= $this->db->plimit($limit);
if ($limit) {
$sql .= $this->db->plimit($limit);
}
dol_syslog("RemiseCheque::Create", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
while ($row = $this->db->fetch_row($resql))
{
if ($resql) {
while ($row = $this->db->fetch_row($resql)) {
array_push($lines, $row[0]);
}
$this->db->free($resql);
@ -229,25 +225,22 @@ class RemiseCheque extends CommonObject
}
}
if ($this->id > 0 && $this->errno == 0)
{
foreach ($lines as $lineid)
{
if ($this->id > 0 && $this->errno == 0) {
foreach ($lines as $lineid) {
$checkremise = false;
foreach ($toRemise as $linetoremise)
{
if ($linetoremise == $lineid) $checkremise = true;
foreach ($toRemise as $linetoremise) {
if ($linetoremise == $lineid) {
$checkremise = true;
}
}
if ($checkremise)
{
if ($checkremise) {
$sql = "UPDATE ".MAIN_DB_PREFIX."bank";
$sql .= " SET fk_bordereau = ".$this->id;
$sql .= " WHERE rowid = ".$lineid;
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$this->errno = -18;
dol_syslog("RemiseCheque::Create Error update bank ".$this->errno, LOG_ERR);
}
@ -255,10 +248,8 @@ class RemiseCheque extends CommonObject
}
}
if ($this->id > 0 && $this->errno == 0)
{
if ($this->updateAmount() <> 0)
{
if ($this->id > 0 && $this->errno == 0) {
if ($this->updateAmount() <> 0) {
$this->errno = -1027;
dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR);
}
@ -269,14 +260,12 @@ class RemiseCheque extends CommonObject
$this->errno = $this->db->lasterrno();
}
if (!$this->errno && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
{
if (!$this->errno && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS)) {
$res = $this->validate($user);
//if ($res < 0) $error++;
}
if (!$this->errno)
{
if (!$this->errno) {
$this->db->commit();
dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
return $this->id;
@ -305,8 +294,7 @@ class RemiseCheque extends CommonObject
$sql .= " AND entity = ".$conf->entity;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->affected_rows($resql);
if ($num <> 1) {
@ -320,16 +308,14 @@ class RemiseCheque extends CommonObject
$sql .= " WHERE fk_bordereau = ".$this->id;
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$this->errno = -1028;
dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)");
}
}
}
if ($this->errno === 0)
{
if ($this->errno === 0) {
$this->db->commit();
} else {
$this->db->rollback();
@ -355,8 +341,7 @@ class RemiseCheque extends CommonObject
$numref = $this->getNextNumRef();
if ($this->errno == 0 && $numref)
{
if ($this->errno == 0 && $numref) {
$sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
$sql .= " SET statut = 1, ref = '".$this->db->escape($numref)."'";
$sql .= " WHERE rowid = ".$this->id;
@ -365,12 +350,10 @@ class RemiseCheque extends CommonObject
dol_syslog("RemiseCheque::Validate", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->affected_rows($resql);
if ($num == 1)
{
if ($num == 1) {
$this->ref = $numref;
$this->statut = 1;
} else {
@ -384,8 +367,7 @@ class RemiseCheque extends CommonObject
}
// Commit/Rollback
if ($this->errno == 0)
{
if ($this->errno == 0) {
$this->db->commit();
return 1;
} else {
@ -408,12 +390,15 @@ class RemiseCheque extends CommonObject
$langs->load("bills");
// Clean parameters (if not defined or using deprecated value)
if (empty($conf->global->CHEQUERECEIPTS_ADDON)) $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
elseif ($conf->global->CHEQUERECEIPTS_ADDON == 'thyme') $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_thyme';
elseif ($conf->global->CHEQUERECEIPTS_ADDON == 'mint') $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
if (empty($conf->global->CHEQUERECEIPTS_ADDON)) {
$conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
} elseif ($conf->global->CHEQUERECEIPTS_ADDON == 'thyme') {
$conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_thyme';
} elseif ($conf->global->CHEQUERECEIPTS_ADDON == 'mint') {
$conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
}
if (!empty($conf->global->CHEQUERECEIPTS_ADDON))
{
if (!empty($conf->global->CHEQUERECEIPTS_ADDON)) {
$mybool = false;
$file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
@ -426,21 +411,18 @@ class RemiseCheque extends CommonObject
$dir = dol_buildpath($reldir."core/modules/cheque/");
// Load file with numbering class (if found)
if (is_file($dir.$file) && is_readable($dir.$file))
{
if (is_file($dir.$file) && is_readable($dir.$file)) {
$mybool |= include_once $dir.$file;
}
}
// For compatibility
if (!$mybool)
{
if (!$mybool) {
$file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
$classname = "mod_chequereceipt_".$conf->global->CHEQUERECEIPTS_ADDON;
$classname = preg_replace('/\-.*$/', '', $classname);
// Include file with class
foreach ($conf->file->dol_document_root as $dirroot)
{
foreach ($conf->file->dol_document_root as $dirroot) {
$dir = $dirroot."/core/modules/cheque/";
// Load file with numbering class (if found)
@ -450,8 +432,7 @@ class RemiseCheque extends CommonObject
}
}
if (!$mybool)
{
if (!$mybool) {
dol_print_error('', "Failed to include file ".$file);
return '';
}
@ -490,7 +471,9 @@ class RemiseCheque extends CommonObject
// phpcs:enable
global $conf, $langs;
if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe
if ($user->socid) {
return -1; // protection pour eviter appel par utilisateur externe
}
$sql = "SELECT b.rowid, b.datev as datefin";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
@ -502,8 +485,7 @@ class RemiseCheque extends CommonObject
$sql .= " AND b.amount > 0";
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$langs->load("banks");
$now = dol_now();
@ -514,8 +496,7 @@ class RemiseCheque extends CommonObject
$response->url = DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank';
$response->img = img_object('', "payment");
while ($obj = $this->db->fetch_object($resql))
{
while ($obj = $this->db->fetch_object($resql)) {
$response->nbtodo++;
if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) {
@ -543,7 +524,9 @@ class RemiseCheque extends CommonObject
// phpcs:enable
global $user;
if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe
if ($user->socid) {
return -1; // protection pour eviter appel par utilisateur externe
}
$sql = "SELECT count(b.rowid) as nb";
$sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
@ -554,10 +537,8 @@ class RemiseCheque extends CommonObject
$sql .= " AND b.amount > 0";
$resql = $this->db->query($sql);
if ($resql)
{
while ($obj = $this->db->fetch_object($resql))
{
if ($resql) {
while ($obj = $this->db->fetch_object($resql)) {
$this->nb["cheques"] = $obj->nb;
}
$this->db->free($resql);
@ -581,7 +562,9 @@ class RemiseCheque extends CommonObject
{
global $langs, $conf;
if (empty($model)) $model = 'blochet';
if (empty($model)) {
$model = 'blochet';
}
dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
@ -589,8 +572,7 @@ class RemiseCheque extends CommonObject
// Charge le modele
$file = "pdf_".$model.".class.php";
if (file_exists($dir.$file))
{
if (file_exists($dir.$file)) {
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
include_once $dir.$file;
@ -609,11 +591,9 @@ class RemiseCheque extends CommonObject
dol_syslog("RemiseCheque::generatePdf", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$i = 0;
while ($objp = $this->db->fetch_object($result))
{
while ($objp = $this->db->fetch_object($result)) {
$docmodel->lines[$i] = new stdClass();
$docmodel->lines[$i]->bank_chq = $objp->banque;
$docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
@ -636,8 +616,7 @@ class RemiseCheque extends CommonObject
// output format that does not support UTF8.
$sav_charseSupprimert_output = $outputlangs->charset_output;
$result = $docmodel->write_file($this, $conf->bank->dir_output.'/checkdeposits', $this->ref, $outputlangs);
if ($result > 0)
{
if ($result > 0) {
//$outputlangs->charset_output=$sav_charset_output;
return 1;
} else {
@ -671,10 +650,8 @@ class RemiseCheque extends CommonObject
$sql .= " WHERE fk_bordereau = ".$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
while ($row = $this->db->fetch_row($resql))
{
if ($resql) {
while ($row = $this->db->fetch_row($resql)) {
$total += $row[0];
$nb++;
}
@ -688,8 +665,7 @@ class RemiseCheque extends CommonObject
$sql .= " AND entity = ".$conf->entity;
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$this->errno = -1030;
dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)");
}
@ -698,8 +674,7 @@ class RemiseCheque extends CommonObject
dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)");
}
if ($this->errno === 0)
{
if ($this->errno === 0) {
$this->db->commit();
} else {
$this->db->rollback();
@ -719,16 +694,14 @@ class RemiseCheque extends CommonObject
{
$this->errno = 0;
if ($this->id > 0)
{
if ($this->id > 0) {
$sql = "UPDATE ".MAIN_DB_PREFIX."bank";
$sql .= " SET fk_bordereau = 0";
$sql .= " WHERE rowid = ".((int) $account_id);
$sql .= " AND fk_bordereau = ".((int) $this->id);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$this->updateAmount();
} else {
$this->errno = -1032;
@ -759,8 +732,8 @@ class RemiseCheque extends CommonObject
/* Conciliation is allowed because when check is returned, a new line is created onto bank transaction log.
if ($bankline->rappro)
{
$this->error='ActionRefusedLineAlreadyConciliated';
return -1;
$this->error='ActionRefusedLineAlreadyConciliated';
return -1;
}*/
$this->db->begin();
@ -776,16 +749,14 @@ class RemiseCheque extends CommonObject
$sql .= ' WHERE pf.fk_paiement = '.$payment->id;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$rejectedPayment = new Paiement($this->db);
$rejectedPayment->amounts = array();
$rejectedPayment->datepaye = $rejection_date;
$rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement', 'code', 'id', 1);
$rejectedPayment->num_payment = $payment->num_payment;
while ($obj = $this->db->fetch_object($resql))
{
while ($obj = $this->db->fetch_object($resql)) {
$invoice = new Facture($this->db);
$invoice->fetch($obj->fk_facture);
$invoice->setUnpaid($user);
@ -794,15 +765,12 @@ class RemiseCheque extends CommonObject
}
$result = $rejectedPayment->create($user);
if ($result > 0)
{
if ($result > 0) {
// We created a negative payment, we also add the line as bank transaction
$result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', $bankaccount, '', '');
if ($result > 0)
{
if ($result > 0) {
$result = $payment->reject();
if ($result > 0)
{
if ($result > 0) {
$this->db->commit();
return $rejectedPayment->id;
} else {
@ -847,8 +815,7 @@ class RemiseCheque extends CommonObject
$sql .= " AND entity = ".$conf->entity;
$result = $this->db->query($sql);
if (!$result)
{
if (!$result) {
$this->errno = -1035;
}
$row = $this->db->fetch_row($result);
@ -860,8 +827,7 @@ class RemiseCheque extends CommonObject
$sql .= " AND entity = ".$conf->entity;
$result = $this->db->query($sql);
if (!$result)
{
if (!$result) {
$this->errno = -1035;
}
$row = $this->db->fetch_row($result);
@ -882,16 +848,14 @@ class RemiseCheque extends CommonObject
public function set_date($user, $date)
{
// phpcs:enable
if ($user->rights->banque->cheque)
{
if ($user->rights->banque->cheque) {
$sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
$sql .= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null');
$sql .= " WHERE rowid = ".$this->id;
dol_syslog("RemiseCheque::set_date", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$this->date_bordereau = $date;
return 1;
} else {
@ -914,16 +878,14 @@ class RemiseCheque extends CommonObject
public function set_number($user, $ref)
{
// phpcs:enable
if ($user->rights->banque->cheque)
{
if ($user->rights->banque->cheque) {
$sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
$sql .= " SET ref = '".$ref."'";
$sql .= " WHERE rowid = ".$this->id;
dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
return 1;
} else {
$this->error = $this->db->error();
@ -979,33 +941,40 @@ class RemiseCheque extends CommonObject
$url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id;
if ($option != 'nolink')
{
if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
$add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
}
$linkclose = '';
if (empty($notooltip))
{
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
if (empty($notooltip)) {
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowCheckReceipt");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
} else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
} else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
$linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
if ($withpicto) {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto != 2) {
$result .= $this->ref;
}
$result .= $linkend;
return $result;
@ -1033,8 +1002,7 @@ class RemiseCheque extends CommonObject
public function LibStatut($status, $mode = 0)
{
// phpcs:enable
if (empty($this->labelStatus) || empty($this->labelStatusShort))
{
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;
$langs->load('compta');
$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('ToValidate');
@ -1044,7 +1012,9 @@ class RemiseCheque extends CommonObject
}
$statusType = 'status'.$status;
if ($status == self::STATUS_VALIDATED) $statusType = 'status4';
if ($status == self::STATUS_VALIDATED) {
$statusType = 'status4';
}
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}

View File

@ -32,7 +32,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->loadLangs(array('banks', 'categories', 'compta', 'bills'));
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', '', '');
@ -97,8 +99,7 @@ $sql .= " ORDER BY bc.date_bordereau DESC, rowid DESC";
$sql .= $db->plimit($max);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
@ -110,8 +111,7 @@ if ($resql)
print '<th class="right">'.$langs->trans("Status").'</th>';
print "</tr>\n";
while ($objp = $db->fetch_object($resql))
{
while ($objp = $db->fetch_object($resql)) {
$checkdepositstatic->id = $objp->rowid;
$checkdepositstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
$checkdepositstatic->statut = $objp->statut;

View File

@ -35,7 +35,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$langs->loadLangs(array('banks', 'categories', 'bills'));
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'banque', '', '');
$search_ref = GETPOST('search_ref', 'alpha');
@ -46,12 +48,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "dp";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "dp";
}
$year = GETPOST("year");
$month = GETPOST("month");
@ -67,8 +75,7 @@ $accountstatic = new Account($db);
*/
// If click on purge search criteria ?
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
$search_ref = '';
$search_amount = '';
$search_account = '';
@ -93,20 +100,24 @@ $sql .= " WHERE bc.fk_bank_account = ba.rowid";
$sql .= " AND bc.entity = ".$conf->entity;
// Search criteria
if ($search_ref) $sql .= natural_search("bc.ref", $search_ref);
if ($search_account > 0) $sql .= " AND bc.fk_bank_account=".$search_account;
if ($search_amount) $sql .= natural_search("bc.amount", price2num($search_amount));
if ($search_ref) {
$sql .= natural_search("bc.ref", $search_ref);
}
if ($search_account > 0) {
$sql .= " AND bc.fk_bank_account=".$search_account;
}
if ($search_amount) {
$sql .= natural_search("bc.amount", price2num($search_amount));
}
$sql .= dolSqlDateFilter('bc.date_bordereau', 0, $month, $year);
$sql .= $db->order($sortfield, $sortorder);
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@ -116,20 +127,27 @@ $sql .= $db->plimit($limit + 1, $offset);
//print "$sql";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.$contextpage;
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.$limit;
}
$url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?action=new';
if (!empty($socid)) $url .= '&socid='.$socid;
if (!empty($socid)) {
$url .= '&socid='.$socid;
}
$newcardbutton = dolGetButtonTitle($langs->trans('NewCheckDeposit'), '', 'fa fa-plus-circle', $url, '', $user->rights->banque->cheque);
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
@ -150,7 +168,9 @@ if ($resql)
print '<input class="flat" type="text" size="4" name="search_ref" value="'.$search_ref.'">';
print '</td>';
print '<td class="liste_titre" align="center">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
}
print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
$formother->select_year($year ? $year : -1, 'year', 1, 20, 5);
print '</td>';
@ -178,10 +198,8 @@ if ($resql)
print_liste_field_titre('');
print "</tr>\n";
if ($num > 0)
{
while ($i < min($num, $limit))
{
if ($num > 0) {
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($resql);
print '<tr class="oddeven">';
@ -199,8 +217,11 @@ if ($resql)
// Bank
print '<td>';
if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"), 'account').' '.$objp->label.'</a>';
else print '&nbsp;';
if ($objp->bid) {
print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"), 'account').' '.$objp->label.'</a>';
} else {
print '&nbsp;';
}
print '</td>';
// Number of cheques
@ -220,9 +241,9 @@ if ($resql)
$i++;
}
} else {
print '<tr class="oddeven">';
print '<td colspan="7" class="opacitymedium">'.$langs->trans("None")."</td>";
print '</tr>';
print '<tr class="oddeven">';
print '<td colspan="7" class="opacitymedium">'.$langs->trans("None")."</td>";
print '</tr>';
}
print "</table>";
print "</div>";

View File

@ -168,18 +168,17 @@ class Paiement extends CommonObject
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
$sql .= ' WHERE p.entity IN ('.getEntity('invoice').')';
if ($id > 0)
if ($id > 0) {
$sql .= ' AND p.rowid = '.$id;
elseif ($ref)
} elseif ($ref) {
$sql .= " AND p.ref = '".$ref."'";
elseif ($fk_bank)
} elseif ($fk_bank) {
$sql .= ' AND p.fk_bank = '.$fk_bank;
}
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -239,8 +238,7 @@ class Paiement extends CommonObject
$totalamount_converted = 0;
$atleastonepaymentnotnull = 0;
if ($way == 'dolibarr')
{
if ($way == 'dolibarr') {
$amounts = &$this->amounts;
$amounts_to_update = &$this->multicurrency_amounts;
} else {
@ -248,8 +246,7 @@ class Paiement extends CommonObject
$amounts_to_update = &$this->amounts;
}
foreach ($amounts as $key => $value) // How payment is dispatch
{
foreach ($amounts as $key => $value) { // How payment is dispatch
$value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
$totalamount_converted += $value_converted;
$amounts_to_update[$key] = price2num($value_converted, 'MT');
@ -257,15 +254,16 @@ class Paiement extends CommonObject
$newvalue = price2num($value, 'MT');
$amounts[$key] = $newvalue;
$totalamount += $newvalue;
if (!empty($newvalue)) $atleastonepaymentnotnull++;
if (!empty($newvalue)) {
$atleastonepaymentnotnull++;
}
}
$totalamount = price2num($totalamount);
$totalamount_converted = price2num($totalamount_converted);
// Check parameters
if (empty($totalamount) && empty($atleastonepaymentnotnull)) // We accept negative amounts for withdraw reject but not empty arrays
{
if (empty($totalamount) && empty($atleastonepaymentnotnull)) { // We accept negative amounts for withdraw reject but not empty arrays
$this->errors[] = 'TotalAmountEmpty';
$this->error = 'TotalAmountEmpty';
return -1;
@ -281,8 +279,7 @@ class Paiement extends CommonObject
$this->ref_ext = '';
}
if ($way == 'dolibarr')
{
if ($way == 'dolibarr') {
$total = $totalamount;
$mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
} else {
@ -298,30 +295,25 @@ class Paiement extends CommonObject
$sql .= "'".$this->db->escape($num_payment)."', '".$this->db->escape($note)."', ".($this->ext_payment_id ? "'".$this->db->escape($this->ext_payment_id)."'" : "null").", ".($this->ext_payment_site ? "'".$this->db->escape($this->ext_payment_site)."'" : "null").", ".$user->id.", ".((float) $this->pos_change).")";
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
// Insert links amount / invoices
foreach ($this->amounts as $key => $amount)
{
foreach ($this->amounts as $key => $amount) {
$facid = $key;
if (is_numeric($amount) && $amount <> 0)
{
if (is_numeric($amount) && $amount <> 0) {
$amount = price2num($amount);
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount)';
$sql .= ' VALUES ('.$facid.', '.$this->id.', \''.$amount.'\', \''.$this->multicurrency_amounts[$key].'\')';
dol_syslog(get_class($this).'::create Amount line '.$key.' insert paiement_facture', LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$invoice = new Facture($this->db);
$invoice->fetch($facid);
// If we want to closed payed invoices
if ($closepaidinvoices)
{
if ($closepaidinvoices) {
$paiement = $invoice->getSommePaiement();
$creditnotes = $invoice->getSumCreditNotesUsed();
$deposits = $invoice->getSumDepositsUsed();
@ -339,13 +331,15 @@ class Paiement extends CommonObject
Facture::TYPE_SITUATION
);
if (!in_array($invoice->type, $affected_types)) dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
elseif ($remaintopay) dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more.");
if (!in_array($invoice->type, $affected_types)) {
dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
} elseif ($remaintopay) {
dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more.");
}
//else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
else {
// If invoice is a down payment, we also convert down payment to discount
if ($invoice->type == Facture::TYPE_DEPOSIT)
{
if ($invoice->type == Facture::TYPE_DEPOSIT) {
$amount_ht = $amount_tva = $amount_ttc = array();
$multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
@ -388,19 +382,16 @@ class Paiement extends CommonObject
}
}
if ($error)
{
if ($error) {
setEventMessages($discount->error, $discount->errors, 'errors');
$error++;
}
}
// Set invoice to paid
if (!$error)
{
if (!$error) {
$result = $invoice->setPaid($user, '', '');
if ($result < 0)
{
if ($result < 0) {
$this->error = $invoice->error;
$this->errors = $invoice->errors;
$error++;
@ -410,8 +401,7 @@ class Paiement extends CommonObject
}
// Regenerate documents of invoices
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
dol_syslog(get_class($this).'::create Regenerate the document after inserting payment for thirdparty default_lang='.(is_object($invoice->thirdparty) ? $invoice->thirdparty->default_lang : 'null'), LOG_DEBUG);
$newlang = '';
@ -440,11 +430,12 @@ class Paiement extends CommonObject
}
}
if (!$error) // All payments into $this->amounts were recorded without errors
{
if (!$error) { // All payments into $this->amounts were recorded without errors
// Appel des triggers
$result = $this->call_trigger('PAYMENT_CUSTOMER_CREATE', $user);
if ($result < 0) { $error++; }
if ($result < 0) {
$error++;
}
// Fin appel triggers
}
} else {
@ -452,8 +443,7 @@ class Paiement extends CommonObject
$error++;
}
if (!$error)
{
if (!$error) {
$this->amount = $total;
$this->total = $total; // deprecated
$this->multicurrency_amount = $mtotal;
@ -487,10 +477,8 @@ class Paiement extends CommonObject
// Verifier si paiement porte pas sur une facture classee
// Si c'est le cas, on refuse la suppression
$billsarray = $this->getBillsArray('fk_statut > 1');
if (is_array($billsarray))
{
if (count($billsarray))
{
if (is_array($billsarray)) {
if (count($billsarray)) {
$this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
$this->db->rollback();
return -1;
@ -501,8 +489,7 @@ class Paiement extends CommonObject
}
// Delete bank urls. If payment is on a conciliated line, return error.
if ($bank_line_id > 0)
{
if ($bank_line_id > 0) {
$accline = new AccountLine($this->db);
$result = $accline->fetch($bank_line_id);
@ -512,8 +499,7 @@ class Paiement extends CommonObject
// Delete bank account url lines linked to payment
$result = $accline->delete_urls($user);
if ($result < 0)
{
if ($result < 0) {
$this->error = $accline->error;
$this->db->rollback();
return -3;
@ -521,20 +507,17 @@ class Paiement extends CommonObject
// Delete bank account lines linked to payment
$result = $accline->delete($user);
if ($result < 0)
{
if ($result < 0) {
$this->error = $accline->error;
$this->db->rollback();
return -4;
}
}
if (!$notrigger)
{
if (!$notrigger) {
// Call triggers
$result = $this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
if ($result < 0)
{
if ($result < 0) {
$this->db->rollback();
return -1;
}
@ -546,14 +529,12 @@ class Paiement extends CommonObject
$sql .= ' WHERE fk_paiement = '.$this->id;
dol_syslog($sql);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
$sql .= ' WHERE rowid = '.$this->id;
dol_syslog($sql);
$result = $this->db->query($sql);
if (!$result)
{
if (!$result) {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -3;
@ -590,10 +571,8 @@ class Paiement extends CommonObject
$error = 0;
$bank_line_id = 0;
if (!empty($conf->banque->enabled))
{
if ($accountid <= 0)
{
if (!empty($conf->banque->enabled)) {
if ($accountid <= 0) {
$this->error = 'Bad value for parameter accountid='.$accountid;
dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
return -1;
@ -611,12 +590,18 @@ class Paiement extends CommonObject
$result = $acc->fetch($this->fk_account);
$totalamount = $this->amount;
if (empty($totalamount)) $totalamount = $this->total; // For backward compatibility
if (empty($totalamount)) {
$totalamount = $this->total; // For backward compatibility
}
// if dolibarr currency != bank currency then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me)
if (!empty($conf->multicurrency->enabled) && $conf->currency != $acc->currency_code) $totalamount = $this->multicurrency_amount;
if (!empty($conf->multicurrency->enabled) && $conf->currency != $acc->currency_code) {
$totalamount = $this->multicurrency_amount;
}
if ($mode == 'payment_supplier') $totalamount = -$totalamount;
if ($mode == 'payment_supplier') {
$totalamount = -$totalamount;
}
// Insert payment into llx_bank
$bank_line_id = $acc->addline(
@ -634,26 +619,25 @@ class Paiement extends CommonObject
// Mise a jour fk_bank dans llx_paiement
// On connait ainsi le paiement qui a genere l'ecriture bancaire
if ($bank_line_id > 0)
{
if ($bank_line_id > 0) {
$result = $this->update_fk_bank($bank_line_id);
if ($result <= 0)
{
if ($result <= 0) {
$error++;
dol_print_error($this->db);
}
// Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
if (!$error)
{
if (!$error) {
$url = '';
if ($mode == 'payment') $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
if ($mode == 'payment_supplier') $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
if ($url)
{
if ($mode == 'payment') {
$url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
}
if ($mode == 'payment_supplier') {
$url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
}
if ($url) {
$result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
if ($result <= 0)
{
if ($result <= 0) {
$error++;
dol_print_error($this->db);
}
@ -662,18 +646,14 @@ class Paiement extends CommonObject
// Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
//if (! $error && $label != '(WithdrawalPayment)')
if (!$error)
{
if (!$error) {
$linkaddedforthirdparty = array();
foreach ($this->amounts as $key => $value) // We should have invoices always for same third party but we loop in case of.
{
if ($mode == 'payment')
{
foreach ($this->amounts as $key => $value) { // We should have invoices always for same third party but we loop in case of.
if ($mode == 'payment') {
$fac = new Facture($this->db);
$fac->fetch($key);
$fac->fetch_thirdparty();
if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) // Not yet done for this thirdparty
{
if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
$result = $acc->add_url_line(
$bank_line_id,
$fac->thirdparty->id,
@ -681,17 +661,17 @@ class Paiement extends CommonObject
$fac->thirdparty->name,
'company'
);
if ($result <= 0) dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
if ($result <= 0) {
dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
}
$linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
}
}
if ($mode == 'payment_supplier')
{
if ($mode == 'payment_supplier') {
$fac = new FactureFournisseur($this->db);
$fac->fetch($key);
$fac->fetch_thirdparty();
if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) // Not yet done for this thirdparty
{
if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
$result = $acc->add_url_line(
$bank_line_id,
$fac->thirdparty->id,
@ -699,7 +679,9 @@ class Paiement extends CommonObject
$fac->thirdparty->name,
'company'
);
if ($result <= 0) dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
if ($result <= 0) {
dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
}
$linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
}
}
@ -717,11 +699,12 @@ class Paiement extends CommonObject
);
}
if (!$error && !$notrigger)
{
if (!$error && !$notrigger) {
// Appel des triggers
$result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user);
if ($result < 0) { $error++; }
if ($result < 0) {
$error++;
}
// Fin appel triggers
}
} else {
@ -729,16 +712,14 @@ class Paiement extends CommonObject
$error++;
}
if (!$error)
{
if (!$error) {
$this->db->commit();
} else {
$this->db->rollback();
}
}
if (!$error)
{
if (!$error) {
return $bank_line_id;
} else {
return -1;
@ -761,8 +742,7 @@ class Paiement extends CommonObject
dol_syslog(get_class($this).'::update_fk_bank', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
return 1;
} else {
$this->error = $this->db->lasterror();
@ -783,8 +763,7 @@ class Paiement extends CommonObject
// phpcs:enable
$error = 0;
if (!empty($date) && $this->statut != 1)
{
if (!empty($date) && $this->statut != 1) {
$this->db->begin();
dol_syslog(get_class($this)."::update_date with date = ".$date, LOG_DEBUG);
@ -794,8 +773,7 @@ class Paiement extends CommonObject
$sql .= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql);
if (!$result)
{
if (!$result) {
$error++;
$this->error = 'Error -1 '.$this->db->error();
}
@ -808,18 +786,15 @@ class Paiement extends CommonObject
$sql .= " AND rappro = 0";
$result = $this->db->query($sql);
if (!$result)
{
if (!$result) {
$error++;
$this->error = 'Error -1 '.$this->db->error();
}
if (!$error)
{
if (!$error) {
}
if (!$error)
{
if (!$error) {
$this->datepaye = $date;
$this->date = $date;
@ -850,8 +825,7 @@ class Paiement extends CommonObject
dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$this->num_payment = $this->db->escape($num);
return 0;
} else {
@ -886,8 +860,7 @@ class Paiement extends CommonObject
dol_syslog(get_class($this).'::valide', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
return 1;
} else {
$this->error = $this->db->lasterror();
@ -908,8 +881,7 @@ class Paiement extends CommonObject
dol_syslog(get_class($this).'::reject', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
return 1;
} else {
$this->error = $this->db->lasterror();
@ -933,20 +905,16 @@ class Paiement extends CommonObject
dol_syslog(get_class($this).'::info', LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
if ($obj->fk_user_creat)
{
if ($obj->fk_user_creat) {
$cuser = new User($this->db);
$cuser->fetch($obj->fk_user_creat);
$this->user_creation = $cuser;
}
if ($obj->fk_user_modif)
{
if ($obj->fk_user_modif) {
$muser = new User($this->db);
$muser->fetch($obj->fk_user_modif);
$this->user_modification = $muser;
@ -971,16 +939,16 @@ class Paiement extends CommonObject
$sql = 'SELECT pf.fk_facture';
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'facture as f'; // We keep link on invoice to allow use of some filters on invoice
$sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = '.$this->id;
if ($filter) $sql .= ' AND '.$filter;
if ($filter) {
$sql .= ' AND '.$filter;
}
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$i = 0;
$num = $this->db->num_rows($resql);
$billsarray = array();
while ($i < $num)
{
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$billsarray[$i] = $obj->fk_facture;
$i++;
@ -1005,14 +973,12 @@ class Paiement extends CommonObject
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
$sql .= ' WHERE pf.fk_paiement = '.$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$i = 0;
$num = $this->db->num_rows($resql);
$amounts = array();
while ($i < $num)
{
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$amounts[$obj->fk_facture] = $obj->amount;
$i++;
@ -1040,12 +1006,15 @@ class Paiement extends CommonObject
$langs->load("bills");
// Clean parameters (if not defined or using deprecated value)
if (empty($conf->global->PAYMENT_ADDON)) $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
elseif ($conf->global->PAYMENT_ADDON == 'ant') $conf->global->PAYMENT_ADDON = 'mod_payment_ant';
elseif ($conf->global->PAYMENT_ADDON == 'cicada') $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
if (empty($conf->global->PAYMENT_ADDON)) {
$conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
} elseif ($conf->global->PAYMENT_ADDON == 'ant') {
$conf->global->PAYMENT_ADDON = 'mod_payment_ant';
} elseif ($conf->global->PAYMENT_ADDON == 'cicada') {
$conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
}
if (!empty($conf->global->PAYMENT_ADDON))
{
if (!empty($conf->global->PAYMENT_ADDON)) {
$mybool = false;
$file = $conf->global->PAYMENT_ADDON.".php";
@ -1058,21 +1027,18 @@ class Paiement extends CommonObject
$dir = dol_buildpath($reldir."core/modules/payment/");
// Load file with numbering class (if found)
if (is_file($dir.$file) && is_readable($dir.$file))
{
if (is_file($dir.$file) && is_readable($dir.$file)) {
$mybool |= include_once $dir.$file;
}
}
// For compatibility
if (!$mybool)
{
if (!$mybool) {
$file = $conf->global->PAYMENT_ADDON.".php";
$classname = "mod_payment_".$conf->global->PAYMENT_ADDON;
$classname = preg_replace('/\-.*$/', '', $classname);
// Include file with class
foreach ($conf->file->dol_document_root as $dirroot)
{
foreach ($conf->file->dol_document_root as $dirroot) {
$dir = $dirroot."/core/modules/payment/";
// Load file with numbering class (if found)
@ -1082,8 +1048,7 @@ class Paiement extends CommonObject
}
}
if (!$mybool)
{
if (!$mybool) {
dol_print_error('', "Failed to include file ".$file);
return '';
}
@ -1119,12 +1084,9 @@ class Paiement extends CommonObject
global $conf;
$way = 'dolibarr';
if (!empty($conf->multicurrency->enabled))
{
foreach ($this->multicurrency_amounts as $value)
{
if (!empty($value)) // one value found then payment is in invoice currency
{
if (!empty($conf->multicurrency->enabled)) {
foreach ($this->multicurrency_amounts as $value) {
if (!empty($value)) { // one value found then payment is in invoice currency
$way = 'customer';
break;
}
@ -1172,31 +1134,30 @@ class Paiement extends CommonObject
{
global $conf, $langs;
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
if (!empty($conf->dol_no_mouse_hover)) {
$notooltip = 1; // Force disable tooltips
}
$result = '';
$label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
$label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
$dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
if ($dateofpayment) {
$label .= '<br><strong>'.$langs->trans("Date").':</strong> ';
$tmparray = dol_getdate($dateofpayment);
if ($tmparray['seconds'] == 0 && $tmparray['minutes'] == 0 && ($tmparray['hours'] == 0 || $tmparray['hours'] == 12)) { // We set hours to 0:00 or 12:00 because we don't know it
$label .= dol_print_date($dateofpayment, 'day');
} else { // Hours was set to real date of payment (special case for POS for example)
$label .= dol_print_date($dateofpayment, 'dayhour', 'tzuser');
}
}
if ($mode == 'withlistofinvoices')
{
$dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
if ($dateofpayment) {
$label .= '<br><strong>'.$langs->trans("Date").':</strong> ';
$tmparray = dol_getdate($dateofpayment);
if ($tmparray['seconds'] == 0 && $tmparray['minutes'] == 0 && ($tmparray['hours'] == 0 || $tmparray['hours'] == 12)) { // We set hours to 0:00 or 12:00 because we don't know it
$label .= dol_print_date($dateofpayment, 'day');
} else { // Hours was set to real date of payment (special case for POS for example)
$label .= dol_print_date($dateofpayment, 'dayhour', 'tzuser');
}
}
if ($mode == 'withlistofinvoices') {
$arraybill = $this->getBillsArray();
if (is_array($arraybill) && count($arraybill) > 0)
{
if (is_array($arraybill) && count($arraybill) > 0) {
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$facturestatic = new Facture($this->db);
foreach ($arraybill as $billid)
{
foreach ($arraybill as $billid) {
$facturestatic->fetch($billid);
$label .= '<br> '.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, 1);
}
@ -1204,16 +1165,16 @@ class Paiement extends CommonObject
}
$linkclose = '';
if (empty($notooltip))
{
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
if (empty($notooltip)) {
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowMyObject");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
} else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
} else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
$url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
@ -1222,8 +1183,12 @@ class Paiement extends CommonObject
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto && $withpicto != 2) $result .= ($this->ref ? $this->ref : $this->id);
if ($withpicto) {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto && $withpicto != 2) {
$result .= ($this->ref ? $this->ref : $this->id);
}
$result .= $linkend;
return $result;
@ -1285,10 +1250,10 @@ class Paiement extends CommonObject
if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
}
if ($mode == 6)
{
if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
}*/
{
if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
}*/
return '';
}
@ -1305,14 +1270,11 @@ class Paiement extends CommonObject
// phpcs:enable
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
if (empty($force_thirdparty_id))
{
if (empty($force_thirdparty_id)) {
$billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
if (!empty($billsarray))
{
if (!empty($billsarray)) {
$invoice = new Facture($this->db);
if ($invoice->fetch($billsarray[0]) > 0)
{
if ($invoice->fetch($billsarray[0]) > 0) {
$force_thirdparty_id = $invoice->socid;
}
}

View File

@ -19,8 +19,9 @@
require '../../main.inc.php';
// Security check
if (!$user->admin && $user->socid > 0)
accessforbidden();
if (!$user->admin && $user->socid > 0) {
accessforbidden();
}
/*

View File

@ -44,7 +44,9 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ
$result = restrictedArea($user, $object->element, $object->id, 'paiement', '');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
// Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
// It should be enough because all payments are done on invoices of the same thirdparty.
if ($socid && $socid != $object->thirdparty->id) {

View File

@ -33,7 +33,9 @@
require '../../main.inc.php';
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'facture', $facid, '');
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
@ -70,13 +72,19 @@ $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) $page = 0; // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0; // If $page is not defined, or '' or -1
}
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "p.ref";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "p.ref";
}
$search_all = trim(GETPOSTISSET("search_all") ? GETPOST("search_all", 'alpha') : GETPOST('sall'));
@ -111,7 +119,9 @@ $object = new Paiement($db);
$parameters = array('socid'=>$socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
@ -193,20 +203,37 @@ if (GETPOST("orphelins", "alpha")) {
$sql .= " AND f.fk_soc = ".$socid;
}
if ($userid) {
if ($userid == -1) $sql .= " AND f.fk_user_author IS NULL";
else $sql .= " AND f.fk_user_author = ".$userid;
if ($userid == -1) {
$sql .= " AND f.fk_user_author IS NULL";
} else {
$sql .= " AND f.fk_user_author = ".$userid;
}
}
// Search criteria
$sql .= dolSqlDateFilter("p.datep", $day, $month, $year);
if ($search_ref) $sql .= natural_search('p.ref', $search_ref);
if ($search_account > 0) $sql .= " AND b.fk_account=".$search_account;
if ($search_paymenttype != '') $sql .= " AND c.code='".$db->escape($search_paymenttype)."'";
if ($search_payment_num != '') $sql .= natural_search('p.num_paiement', $search_payment_num);
if ($search_amount) $sql .= natural_search('p.amount', $search_amount, 1);
if ($search_company) $sql .= natural_search('s.nom', $search_company);
if ($search_ref) {
$sql .= natural_search('p.ref', $search_ref);
}
if ($search_account > 0) {
$sql .= " AND b.fk_account=".$search_account;
}
if ($search_paymenttype != '') {
$sql .= " AND c.code='".$db->escape($search_paymenttype)."'";
}
if ($search_payment_num != '') {
$sql .= natural_search('p.num_paiement', $search_payment_num);
}
if ($search_amount) {
$sql .= natural_search('p.amount', $search_amount, 1);
}
if ($search_company) {
$sql .= natural_search('s.nom', $search_company);
}
if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
if ($search_all) {
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
}
// Add where from hooks
$parameters = array();
@ -240,17 +267,25 @@ if (!$resql) {
$num = $db->num_rows($resql);
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
$param .= (GETPOST("orphelins") ? "&orphelins=1" : '');
$param .= ($search_ref ? "&search_ref=".urlencode($search_ref) : '');
$param .= ($search_company ? "&search_company=".urlencode($search_company) : '');
$param .= ($search_amount ? "&search_amount=".urlencode($search_amount) : '');
$param .= ($search_payment_num ? "&search_payment_num=".urlencode($search_payment_num) : '');
if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
@ -261,15 +296,18 @@ print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print_barre_liste($langs->trans("ReceivedCustomersPayments"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'bill', 0, '', '', $limit, 0, 0, 1);
if ($search_all)
{
foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
if ($search_all) {
foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
}
$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
if ($massactionbutton) {
$selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
}
print '<div class="div-table-responsive">';
print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : '').'">';
@ -293,7 +331,9 @@ if (!empty($arrayfields['p.ref']['checked'])) {
// Filter: Date
if (!empty($arrayfields['p.datep']['checked'])) {
print '<td class="liste_titre center">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.dol_escape_htmltag($day).'">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="day" value="'.dol_escape_htmltag($day).'">';
}
print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="month" value="'.dol_escape_htmltag($month).'">';
$formother->select_year($year ? $year : -1, 'year', 1, 20, 5);
print '</td>';
@ -358,16 +398,36 @@ print '</td>';
print "</tr>";
print '<tr class="liste_titre">';
if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['p.datep']['checked'])) print_liste_field_titre($arrayfields['p.datep']['label'], $_SERVER["PHP_SELF"], "p.datep", '', $param, '', $sortfield, $sortorder, 'center ');
if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['c.libelle']['checked'])) print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['p.num_paiement']['checked'])) print_liste_field_titre($arrayfields['p.num_paiement']['label'], $_SERVER["PHP_SELF"], "p.num_paiement", '', $param, '', $sortfield, $sortorder, '', $arrayfields['p.num_paiement']['tooltip']);
if (!empty($arrayfields['transaction']['checked'])) print_liste_field_titre($arrayfields['transaction']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['ba.label']['checked'])) print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER["PHP_SELF"], "ba.label", '', $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['p.amount']['checked'])) print_liste_field_titre($arrayfields['p.amount']['label'], $_SERVER["PHP_SELF"], "p.amount", '', $param, 'class="right"', $sortfield, $sortorder);
if (!empty($arrayfields['p.statut']['checked'])) print_liste_field_titre($arrayfields['p.statut']['label'], $_SERVER["PHP_SELF"], "p.statut", '', $param, 'class="right"', $sortfield, $sortorder);
if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['p.ref']['checked'])) {
print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['p.datep']['checked'])) {
print_liste_field_titre($arrayfields['p.datep']['label'], $_SERVER["PHP_SELF"], "p.datep", '', $param, '', $sortfield, $sortorder, 'center ');
}
if (!empty($arrayfields['s.nom']['checked'])) {
print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['c.libelle']['checked'])) {
print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['p.num_paiement']['checked'])) {
print_liste_field_titre($arrayfields['p.num_paiement']['label'], $_SERVER["PHP_SELF"], "p.num_paiement", '', $param, '', $sortfield, $sortorder, '', $arrayfields['p.num_paiement']['tooltip']);
}
if (!empty($arrayfields['transaction']['checked'])) {
print_liste_field_titre($arrayfields['transaction']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['ba.label']['checked'])) {
print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER["PHP_SELF"], "ba.label", '', $param, '', $sortfield, $sortorder);
}
if (!empty($arrayfields['p.amount']['checked'])) {
print_liste_field_titre($arrayfields['p.amount']['label'], $_SERVER["PHP_SELF"], "p.amount", '', $param, 'class="right"', $sortfield, $sortorder);
}
if (!empty($arrayfields['p.statut']['checked'])) {
print_liste_field_titre($arrayfields['p.statut']['label'], $_SERVER["PHP_SELF"], "p.statut", '', $param, 'class="right"', $sortfield, $sortorder);
}
// Hook fields
$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
@ -401,21 +461,29 @@ while ($i < min($num, $limit)) {
// No
if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
print '<td>'.(($offset * $limit) + $i).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Ref
if (!empty($arrayfields['p.ref']['checked'])) {
print '<td>'.$object->getNomUrl(1).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date
if (!empty($arrayfields['p.datep']['checked'])) {
$dateformatforpayment = 'day';
if (!empty($conf->global->INVOICE_USE_HOURS_FOR_PAYMENT)) $dateformatforpayment = 'dayhour';
if (!empty($conf->global->INVOICE_USE_HOURS_FOR_PAYMENT)) {
$dateformatforpayment = 'dayhour';
}
print '<td class="center">'.dol_print_date($db->jdate($objp->datep), $dateformatforpayment).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Thirdparty
@ -425,26 +493,34 @@ while ($i < min($num, $limit)) {
print $companystatic->getNomUrl(1, '', 24);
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Payment type
if (!empty($arrayfields['c.libelle']['checked'])) {
print '<td>'.$langs->trans("PaymentTypeShort".$objp->paiement_code).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Filter: Cheque number (fund transfer)
if (!empty($arrayfields['p.num_paiement']['checked'])) {
print '<td>'.$objp->num_paiement.'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Bank transaction
if (!empty($arrayfields['transaction']['checked'])) {
$bankline->fetch($objp->fk_bank);
print '<td>'.$bankline->getNomUrl(1, 0).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Bank account
@ -464,13 +540,17 @@ while ($i < min($num, $limit)) {
print $accountstatic->getNomUrl(1);
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Amount
if (!empty($arrayfields['p.amount']['checked'])) {
print '<td class="right">'.price($objp->amount).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
$totalarray['pos'][$checkedCount] = 'amount';
$totalarray['val']['amount'] += $objp->amount;
}
@ -478,16 +558,24 @@ while ($i < min($num, $limit)) {
// Status
if (!empty($arrayfields['p.statut']['checked'])) {
print '<td class="right">';
if ($objp->statut == 0) print '<a href="card.php?id='.$objp->rowid.'&amp;action=valide">';
if ($objp->statut == 0) {
print '<a href="card.php?id='.$objp->rowid.'&amp;action=valide">';
}
print $object->LibStatut($objp->statut, 5);
if ($objp->statut == 0) print '</a>';
if ($objp->statut == 0) {
print '</a>';
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Buttons
print '<td></td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
print '</tr>';
@ -498,10 +586,13 @@ while ($i < min($num, $limit)) {
include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
// If no record found
if ($num == 0)
{
if ($num == 0) {
$colspan = 1;
foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
foreach ($arrayfields as $key => $val) {
if (!empty($val['checked'])) {
$colspan++;
}
}
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
}

View File

@ -33,33 +33,36 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
$action = GETPOST('action', 'aZ09');
$socid = 0;
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
$dir = $conf->facture->dir_output.'/payments';
if (!$user->rights->societe->client->voir || $socid) $dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
if (!$user->rights->societe->client->voir || $socid) {
$dir .= '/private/'.$user->id; // If user has no permission to see all, output dir is specific to user
}
$year = GETPOST('year', 'int');
if (!$year) { $year = date("Y"); }
if (!$year) {
$year = date("Y");
}
// Security check
if (empty($user->rights->facture->lire)) accessforbidden();
if (empty($user->rights->facture->lire)) {
accessforbidden();
}
/*
* Actions
*/
if ($action == 'builddoc')
{
if ($action == 'builddoc') {
$rap = new pdf_paiement($db);
$outputlangs = $langs;
if (GETPOST('lang_id', 'aZ09'))
{
if (GETPOST('lang_id', 'aZ09')) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
}
@ -67,8 +70,7 @@ if ($action == 'builddoc')
// We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8.
$sav_charset_output = $outputlangs->charset_output;
if ($rap->write_file($dir, $_POST["remonth"], $_POST["reyear"], $outputlangs) > 0)
{
if ($rap->write_file($dir, $_POST["remonth"], $_POST["reyear"], $outputlangs) > 0) {
$outputlangs->charset_output = $sav_charset_output;
} else {
$outputlangs->charset_output = $sav_charset_output;
@ -111,15 +113,11 @@ clearstatcache();
// Show link on other years
$linkforyear = array();
$found = 0;
if (is_dir($dir))
{
if (is_dir($dir)) {
$handle = opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file))
{
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file)) {
$found = 1;
$linkforyear[] = $file;
}
@ -127,18 +125,17 @@ if (is_dir($dir))
}
}
asort($linkforyear);
foreach ($linkforyear as $cursoryear)
{
foreach ($linkforyear as $cursoryear) {
print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$cursoryear.'">'.$cursoryear.'</a> &nbsp;';
}
if ($year)
{
if (is_dir($dir.'/'.$year))
{
if ($year) {
if (is_dir($dir.'/'.$year)) {
$handle = opendir($dir.'/'.$year);
if ($found) print '<br>';
if ($found) {
print '<br>';
}
print '<br>';
print '<table width="100%" class="noborder">';
print '<tr class="liste_titre">';
@ -147,12 +144,9 @@ if ($year)
print '<td class="right">'.$langs->trans("Date").'</td>';
print '</tr>';
if (is_resource($handle))
{
while (($file = readdir($handle)) !== false)
{
if (preg_match('/^payment/i', $file))
{
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (preg_match('/^payment/i', $file)) {
$tfile = $dir.'/'.$year.'/'.$file;
$relativepath = $year.'/'.$file;
print '<tr class="oddeven">';

View File

@ -28,8 +28,7 @@ require '../../main.inc.php';
$langs->load("bills");
$socid = 0;
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
@ -39,15 +38,23 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "p.rowid";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "p.rowid";
}
// Security check
if (empty($user->rights->facture->lire)) accessforbidden();
if (empty($user->rights->facture->lire)) {
accessforbidden();
}
/*
@ -65,14 +72,12 @@ llxHeader();
$sql = "SELECT p.rowid, p.datep as dp, p.amount, p.statut";
$sql .= ", c.libelle as paiement_type, p.num_paiement as num_payment";
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
if ($socid)
{
if ($socid) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid";
}
$sql .= " WHERE p.entity IN (".getEntity('invoice').')';
if ($socid)
{
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
$sql .= " AND p.statut = 0";
@ -81,12 +86,10 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@ -95,8 +98,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -111,8 +113,7 @@ if ($resql)
print_liste_field_titre('');
print "</tr>\n";
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$objp = $db->fetch_object($resql);
print '<tr class="oddeven">';
@ -122,8 +123,7 @@ if ($resql)
print '<td class="right">'.price($objp->amount).'</td>';
print '<td class="center">';
if ($objp->statut == 0)
{
if ($objp->statut == 0) {
print '<a href="card.php?id='.$objp->rowid.'&amp;action=valide">'.$langs->trans("PaymentStatusToValidShort").'</a>';
} else {
print "-";

View File

@ -36,8 +36,7 @@ $amounts = array();
// Security check
$socid = 0;
if ($user->socid > 0)
{
if ($user->socid > 0) {
$socid = $user->socid;
}
@ -48,12 +47,10 @@ $charge = new ChargeSociales($db);
* Actions
*/
if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes'))
{
if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) {
$error = 0;
if ($_POST["cancel"])
{
if ($_POST["cancel"]) {
$loc = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid;
header("Location: ".$loc);
exit;
@ -61,48 +58,40 @@ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'y
$datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
if (!$_POST["paiementtype"] > 0)
{
if (!$_POST["paiementtype"] > 0) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
$error++;
$action = 'create';
}
if ($datepaye == '')
{
if ($datepaye == '') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
$error++;
$action = 'create';
}
if (!empty($conf->banque->enabled) && !($_POST["accountid"] > 0))
{
if (!empty($conf->banque->enabled) && !($_POST["accountid"] > 0)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors');
$error++;
$action = 'create';
}
if (!$error)
{
if (!$error) {
$paymentid = 0;
// Read possible payments
foreach ($_POST as $key => $value)
{
if (substr($key, 0, 7) == 'amount_')
{
foreach ($_POST as $key => $value) {
if (substr($key, 0, 7) == 'amount_') {
$other_chid = substr($key, 7);
$amounts[$other_chid] = price2num($_POST[$key]);
}
}
if (count($amounts) <= 0)
{
if (count($amounts) <= 0) {
$error++;
setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors');
$action = 'create';
}
if (!$error)
{
if (!$error) {
$db->begin();
// Create a line of payments
@ -115,30 +104,25 @@ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'y
$paiement->note = GETPOST("note", 'restricthtml');
$paiement->note_private = GETPOST("note", 'restricthtml');
if (!$error)
{
if (!$error) {
$paymentid = $paiement->create($user, (GETPOST('closepaidcontrib') == 'on' ? 1 : 0));
if ($paymentid < 0)
{
if ($paymentid < 0) {
$error++;
setEventMessages($paiement->error, null, 'errors');
$action = 'create';
}
}
if (!$error)
{
if (!$error) {
$result = $paiement->addPaymentToBank($user, 'payment_sc', '(SocialContributionPayment)', GETPOST('accountid', 'int'), '', '');
if (!($result > 0))
{
if (!($result > 0)) {
$error++;
setEventMessages($paiement->error, null, 'errors');
$action = 'create';
}
}
if (!$error)
{
if (!$error) {
$db->commit();
$loc = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid;
header('Location: '.$loc);
@ -161,15 +145,13 @@ $form = new Form($db);
// Form of charge payment creation
if ($action == 'create')
{
if ($action == 'create') {
$charge->fetch($chid);
$charge->accountid = $charge->fk_account ? $charge->fk_account : $charge->accountid;
$charge->paiementtype = $charge->mode_reglement_id ? $charge->mode_reglement_id : $charge->paiementtype;
$total = $charge->amount;
if (!empty($conf->use_javascript_ajax))
{
if (!empty($conf->use_javascript_ajax)) {
print "\n".'<script type="text/javascript" language="javascript">';
//Add js for AutoFill
@ -186,8 +168,7 @@ if ($action == 'create')
print load_fiche_titre($langs->trans("DoPayment"));
print "<br>\n";
if ($mesg)
{
if ($mesg) {
print "<div class=\"error\">$mesg</div>";
}
@ -212,8 +193,7 @@ if ($action == 'create')
$sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
$sql .= " WHERE p.fk_charge = ".$chid;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
$sumpaid = $obj->total;
$db->free();
@ -255,7 +235,7 @@ if ($action == 'create')
print dol_get_fiche_end();
/*
* Other unpaid charges
* Other unpaid charges
*/
$num = 1;
$i = 0;
@ -273,14 +253,12 @@ if ($action == 'create')
$total = 0;
$totalrecu = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $charge;
print '<tr class="oddeven">';
if ($objp->date_ech > 0)
{
if ($objp->date_ech > 0) {
print '<td class="left">'.dol_print_date($objp->date_ech, 'day').'</td>'."\n";
} else {
print "<td align=\"center\"><b>!!!</b></td>\n";
@ -293,12 +271,12 @@ if ($action == 'create')
print '<td class="right">'.price($objp->amount - $sumpaid)."</td>";
print '<td class="center">';
if ($sumpaid < $objp->amount)
{
if ($sumpaid < $objp->amount) {
$namef = "amount_".$objp->id;
$nameRemain = "remain_".$objp->id;
if (!empty($conf->use_javascript_ajax))
if (!empty($conf->use_javascript_ajax)) {
print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'");
}
$remaintopay = $objp->amount - $sumpaid;
print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'">';
@ -313,8 +291,7 @@ if ($action == 'create')
$totalrecu += $objp->am;
$i++;
}
if ($i > 1)
{
if ($i > 1) {
// Print total
print '<tr class="oddeven">';
print '<td colspan="2" class="left">'.$langs->trans("Total").':</td>';

View File

@ -37,8 +37,7 @@ $amounts = array();
// Security check
$socid = 0;
if ($user->socid > 0)
{
if ($user->socid > 0) {
$socid = $user->socid;
}
@ -47,12 +46,10 @@ if ($user->socid > 0)
* Actions
*/
if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes'))
{
if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) {
$error = 0;
if ($_POST["cancel"])
{
if ($_POST["cancel"]) {
$loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid;
header("Location: ".$loc);
exit;
@ -60,92 +57,79 @@ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'y
$datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int'));
if (!(GETPOST("paiementtype", 'int') > 0))
{
if (!(GETPOST("paiementtype", 'int') > 0)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
$error++;
$action = 'create';
$action = 'create';
}
if ($datepaye == '')
{
if ($datepaye == '') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
$error++;
$action = 'create';
$action = 'create';
}
if (!empty($conf->banque->enabled) && !(GETPOST("accountid", 'int') > 0)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors');
$error++;
$action = 'create';
}
if (!empty($conf->banque->enabled) && !(GETPOST("accountid", 'int') > 0))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors');
$error++;
$action = 'create';
}
if (!$error)
{
if (!$error) {
$paymentid = 0;
// Read possible payments
foreach ($_POST as $key => $value)
{
if (substr($key, 0, 7) == 'amount_')
{
foreach ($_POST as $key => $value) {
if (substr($key, 0, 7) == 'amount_') {
$other_chid = substr($key, 7);
$amounts[$other_chid] = price2num(GETPOST($key));
}
}
if (count($amounts) <= 0)
{
$error++;
setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors');
$action = 'create';
}
if (count($amounts) <= 0) {
$error++;
setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors');
$action = 'create';
}
if (!$error)
{
$db->begin();
if (!$error) {
$db->begin();
// Create a line of payments
$paiement = new PaymentVAT($db);
$paiement->chid = $chid;
$paiement->datepaye = $datepaye;
$paiement->amounts = $amounts; // Tableau de montant
$paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml');
$paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
$paiement->note = (string) GETPOST("note", 'restricthtml');
$paiement->note_private = (string) GETPOST("note", 'restricthtml');
// Create a line of payments
$paiement = new PaymentVAT($db);
$paiement->chid = $chid;
$paiement->datepaye = $datepaye;
$paiement->amounts = $amounts; // Tableau de montant
$paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml');
$paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
$paiement->note = (string) GETPOST("note", 'restricthtml');
$paiement->note_private = (string) GETPOST("note", 'restricthtml');
if (!$error) {
$paymentid = $paiement->create($user, (GETPOST('closepaidvat') == 'on' ? 1 : 0));
if ($paymentid < 0)
{
$error++;
setEventMessages($paiement->error, null, 'errors');
$action = 'create';
}
}
if (!$error) {
$paymentid = $paiement->create($user, (GETPOST('closepaidvat') == 'on' ? 1 : 0));
if ($paymentid < 0) {
$error++;
setEventMessages($paiement->error, null, 'errors');
$action = 'create';
}
}
if (!$error)
{
$result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOST('accountid', 'int'), '', '');
if (!($result > 0))
{
$error++;
setEventMessages($paiement->error, null, 'errors');
$action = 'create';
}
}
if (!$error) {
$result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOST('accountid', 'int'), '', '');
if (!($result > 0)) {
$error++;
setEventMessages($paiement->error, null, 'errors');
$action = 'create';
}
}
if (!$error)
{
$db->commit();
$loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid;
header('Location: '.$loc);
exit;
}
else {
$db->rollback();
}
}
if (!$error) {
$db->commit();
$loc = DOL_URL_ROOT.'/compta/tva/card.php?id='.$chid;
header('Location: '.$loc);
exit;
} else {
$db->rollback();
}
}
}
}
@ -160,16 +144,14 @@ $form = new Form($db);
// Formulaire de creation d'un paiement de charge
if ($action == 'create')
{
if ($action == 'create') {
$tva = new Tva($db);
$tva->fetch($chid);
$tva->accountid = $tva->fk_account ? $tva->fk_account : $tva->accountid;
$tva->paiementtype = $tva->type_payment;
$total = $tva->amount;
if (!empty($conf->use_javascript_ajax))
{
if (!empty($conf->use_javascript_ajax)) {
print "\n".'<script type="text/javascript" language="javascript">';
//Add js for AutoFill
@ -249,7 +231,7 @@ if ($action == 'create')
print dol_get_fiche_end();
/*
* Autres charges impayees
* Autres charges impayees
*/
$num = 1;
$i = 0;
@ -267,17 +249,14 @@ if ($action == 'create')
$total = 0;
$totalrecu = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $tva;
print '<tr class="oddeven">';
if ($objp->datev > 0)
{
if ($objp->datev > 0) {
print '<td class="left">'.dol_print_date($objp->datev, 'day').'</td>'."\n";
}
else {
} else {
print "<td align=\"center\"><b>!!!</b></td>\n";
}
@ -289,8 +268,7 @@ if ($action == 'create')
print '<td class="center">';
if ($sumpaid <> $objp->amount)
{
if ($sumpaid <> $objp->amount) {
$namef = "amount_".$objp->id;
$nameRemain = "remain_".$objp->id;
/* Disabled, we autofil the amount with remain to pay by default
@ -300,8 +278,7 @@ if ($action == 'create')
$remaintopay = $objp->amount - $sumpaid;
print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
print '<input type="text" class="right width100" name="'.$namef.'" id="'.$namef.'" value="'.$remaintopay.'">';
}
else {
} else {
print '-';
}
print "</td>";

View File

@ -30,7 +30,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
if (!empty($conf->banque->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
// Load translation files required by the page
$langs->loadLangs(array('bills', 'banks', 'companies'));
@ -39,15 +41,18 @@ $langs->loadLangs(array('bills', 'banks', 'companies'));
$id = GETPOST("id", 'int');
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'aZ09');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
// TODO ajouter regle pour restreindre acces paiement
//$result = restrictedArea($user, 'facture', $id,'');
$object = new PaymentSocialContribution($db);
if ($id > 0)
{
if ($id > 0) {
$result = $object->fetch($id);
if (!$result) dol_print_error($db, 'Failed to get payment id '.$id);
if (!$result) {
dol_print_error($db, 'Failed to get payment id '.$id);
}
}
@ -56,13 +61,11 @@ if ($id > 0)
*/
// Delete payment
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer)
{
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer) {
$db->begin();
$result = $object->delete($user);
if ($result > 0)
{
if ($result > 0) {
$db->commit();
header("Location: ".DOL_URL_ROOT."/compta/sociales/payments.php");
exit;
@ -101,8 +104,7 @@ print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribu
/*
* Deletion confirmation of payment
*/
if ($action == 'delete')
{
if ($action == 'delete') {
print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
}
@ -138,10 +140,8 @@ print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
// Bank account
if (!empty($conf->banque->enabled))
{
if ($object->bank_account)
{
if (!empty($conf->banque->enabled)) {
if ($object->bank_account) {
$bankline = new AccountLine($db);
$bankline->fetch($object->bank_line);
@ -174,8 +174,7 @@ $sql .= ' AND pf.rowid = '.$object->id;
dol_syslog("compta/payment_sc/card.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -190,10 +189,8 @@ if ($resql)
print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
print "</tr>\n";
if ($num > 0)
{
while ($i < $num)
{
if ($num > 0) {
while ($i < $num) {
$objp = $db->fetch_object($resql);
print '<tr class="oddeven">';
@ -216,8 +213,7 @@ if ($resql)
// Amount paid
print '<td class="right">'.price($objp->amount).'</td>';
print "</tr>\n";
if ($objp->paye == 1) // If at least one invoice is paid, disable delete
{
if ($objp->paye == 1) { // If at least one invoice is paid, disable delete
$disable_delete = 1;
}
$total = $total + $objp->amount;
@ -252,12 +248,9 @@ if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
}
*/
if ($action == '')
{
if ($user->rights->tax->charges->supprimer)
{
if (!$disable_delete)
{
if ($action == '') {
if ($user->rights->tax->charges->supprimer) {
if (!$disable_delete) {
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.GETPOST('id', 'int').'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans('Delete').'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';

View File

@ -31,7 +31,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
if (!empty($conf->banque->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
// Load translation files required by the page
$langs->loadLangs(array('bills', 'banks', 'companies'));
@ -40,15 +42,18 @@ $langs->loadLangs(array('bills', 'banks', 'companies'));
$id = GETPOST("id", 'int');
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
// TODO ajouter regle pour restreindre acces paiement
//$result = restrictedArea($user, 'facture', $id,'');
$object = new PaymentVAT($db);
if ($id > 0)
{
if ($id > 0) {
$result = $object->fetch($id);
if (!$result) dol_print_error($db, 'Failed to get payment id '.$id);
if (!$result) {
dol_print_error($db, 'Failed to get payment id '.$id);
}
}
@ -57,20 +62,17 @@ if ($id > 0)
*/
// Delete payment
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer)
{
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer) {
$db->begin();
$result = $object->delete($user);
if ($result > 0)
{
$db->commit();
header("Location: ".DOL_URL_ROOT."/compta/tva/payments.php?mode=tvaonly");
exit;
}
else {
if ($result > 0) {
$db->commit();
header("Location: ".DOL_URL_ROOT."/compta/tva/payments.php?mode=tvaonly");
exit;
} else {
setEventMessages($object->error, $object->errors, 'errors');
$db->rollback();
$db->rollback();
}
}
@ -192,20 +194,18 @@ print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
// Bank account
if (!empty($conf->banque->enabled))
{
if ($object->bank_account)
{
$bankline = new AccountLine($db);
$bankline->fetch($object->bank_line);
if (!empty($conf->banque->enabled)) {
if ($object->bank_account) {
$bankline = new AccountLine($db);
$bankline->fetch($object->bank_line);
print '<tr>';
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
print '<tr>';
print '<td>'.$langs->trans('BankTransactionLine').'</td>';
print '<td colspan="3">';
print $bankline->getNomUrl(1, 0, 'showall');
print '</td>';
print '</tr>';
}
print '</td>';
print '</tr>';
}
}
print '</table>';
@ -231,8 +231,7 @@ $sql .= ' AND pf.rowid = '.$object->id;
dol_syslog("compta/payment_vat/card.php", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -240,17 +239,15 @@ if ($resql)
print '<br><table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('VATDeclaration').'</td>';
//print '<td>'.$langs->trans('Type').'</td>';
//print '<td>'.$langs->trans('Type').'</td>';
print '<td>'.$langs->trans('Label').'</td>';
print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
print '<td class="center">'.$langs->trans('Status').'</td>';
print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
print "</tr>\n";
if ($num > 0)
{
while ($i < $num)
{
if ($num > 0) {
while ($i < $num) {
$objp = $db->fetch_object($resql);
print '<tr class="oddeven">';
@ -261,8 +258,8 @@ if ($resql)
print "</td>\n";
// Type
/* print '<td>';
print $tva->type_label;4
print "</td>\n";*/
print $tva->type_label;4
print "</td>\n";*/
// Label
print '<td>'.$objp->label.'</td>';
// Expected to pay
@ -272,8 +269,7 @@ if ($resql)
// Amount payed
print '<td class="right">'.price($objp->amount).'</td>';
print "</tr>\n";
if ($objp->paye == 1) // If at least one invoice is paid, disable delete
{
if ($objp->paye == 1) { // If at least one invoice is paid, disable delete
$disable_delete = 1;
}
$total = $total + $objp->amount;
@ -284,8 +280,7 @@ if ($resql)
print "</table>\n";
$db->free($resql);
}
else {
} else {
dol_print_error($db);
}
@ -309,15 +304,11 @@ if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
}
*/
if ($action == '')
{
if ($user->rights->tax->charges->supprimer)
{
if (!$disable_delete)
{
if ($action == '') {
if ($user->rights->tax->charges->supprimer) {
if (!$disable_delete) {
print '<a class="butActionDelete" href="card.php?id='.$_GET['id'].'&amp;action=delete">'.$langs->trans('Delete').'</a>';
}
else {
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentVATPaid")).'">'.$langs->trans('Delete').'</a>';
}
}

View File

@ -38,7 +38,9 @@ $langs->loadLangs(array('banks', 'categories', 'withdrawals'));
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'paymentbybanktransfer', '', '');
@ -55,8 +57,7 @@ $result = restrictedArea($user, 'paymentbybanktransfer', '', '');
llxHeader('', $langs->trans("SuppliersStandingOrdersArea"));
if (prelevement_check_config('bank-transfer') < 0)
{
if (prelevement_check_config('bank-transfer') < 0) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Withdraw")), null, 'errors');
}
@ -97,24 +98,28 @@ $sql .= " pfd.date_demande, pfd.amount,";
$sql .= " s.nom as name, s.email, s.rowid as socid, s.tva_intra";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,";
$sql .= " ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
$sql .= " WHERE s.rowid = f.fk_soc";
$sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
$sql .= " AND f.total_ttc > 0";
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS))
{
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
$sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
}
$sql .= " AND pfd.traite = 0";
$sql .= " AND pfd.ext_payment_id IS NULL";
$sql .= " AND pfd.fk_facture_fourn = f.rowid";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -122,10 +127,8 @@ if ($resql)
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th colspan="5">'.$langs->trans("SupplierInvoiceWaitingWithdraw").' ('.$num.')</th></tr>';
if ($num)
{
while ($i < $num && $i < 20)
{
if ($num) {
while ($i < $num && $i < 20) {
$obj = $db->fetch_object($resql);
$invoicestatic->id = $obj->rowid;
@ -186,8 +189,7 @@ $sql .= " ORDER BY datec DESC";
$sql .= $db->plimit($limit);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
@ -202,8 +204,7 @@ if ($result)
print '</tr>';
if ($num > 0) {
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($result);
print '<tr class="oddeven">';

View File

@ -34,7 +34,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'withdrawals'));
// Security check
if ($user->socid > 0) accessforbidden();
if ($user->socid > 0) {
accessforbidden();
}
// Get supervariables
$action = GETPOST('action', 'aZ09');
@ -48,13 +50,19 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortfield) $sortfield = 'pl.fk_soc';
if (!$sortorder) $sortorder = 'DESC';
if (!$sortfield) {
$sortfield = 'pl.fk_soc';
}
if (!$sortorder) {
$sortorder = 'DESC';
}
$object = new BonPrelevement($db);
@ -77,15 +85,14 @@ if (!$user->rights->paymentbybanktransfer->read && $object->type == 'bank-transf
$parameters = array('socid' => $socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook))
{
if ($action == 'confirm_delete')
{
if (empty($reshook)) {
if ($action == 'confirm_delete') {
$res = $object->delete($user);
if ($res > 0)
{
if ($res > 0) {
if ($object->type == 'bank-transfer') {
header("Location: ".DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php');
} else {
@ -96,8 +103,7 @@ if (empty($reshook))
}
// Seems to no be used and replaced with $action == 'infocredit'
if ($action == 'confirm_credite' && GETPOST('confirm', 'alpha') == 'yes')
{
if ($action == 'confirm_credite' && GETPOST('confirm', 'alpha') == 'yes') {
if ($object->statut == 2) {
$res = -1;
setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors');
@ -105,50 +111,46 @@ if (empty($reshook))
$res = $object->set_credite();
}
if ($res >= 0)
{
if ($res >= 0) {
header("Location: card.php?id=".$id);
exit;
}
}
if ($action == 'infotrans' && $user->rights->prelevement->bons->send)
{
if ($action == 'infotrans' && $user->rights->prelevement->bons->send) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
/*
if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $object->ref)
{
$dir = $conf->prelevement->dir_output.'/receipts';
if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $object->ref)
{
$dir = $conf->prelevement->dir_output.'/receipts';
if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0)
{
$object->set_infotrans($user, $dt, GETPOST('methode','alpha'));
}
if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0)
{
$object->set_infotrans($user, $dt, GETPOST('methode','alpha'));
}
header("Location: card.php?id=".$id);
exit;
}
else
{
dol_syslog("Fichier invalide",LOG_WARNING);
$mesg='BadFile';
}*/
header("Location: card.php?id=".$id);
exit;
}
else
{
dol_syslog("Fichier invalide",LOG_WARNING);
$mesg='BadFile';
}*/
$error = $object->set_infotrans($user, $dt, GETPOST('methode', 'alpha'));
if ($error)
{
if ($error) {
header("Location: card.php?id=".$id."&error=$error");
exit;
}
}
// Set direct debit order to credited, create payment and close invoices
if ($action == 'infocredit' && $user->rights->prelevement->bons->credit)
{
if ($action == 'infocredit' && $user->rights->prelevement->bons->credit) {
$dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
if ($object->statut == 2) {
@ -158,9 +160,8 @@ if (empty($reshook))
$error = $object->set_infocredit($user, $dt);
}
if ($error)
{
setEventMessages($object->error, $object->errors, 'errors');
if ($error) {
setEventMessages($object->error, $object->errors, 'errors');
}
}
}
@ -175,13 +176,11 @@ $form = new Form($db);
llxHeader('', $langs->trans("WithdrawalsReceipts"));
if ($id > 0 || $ref)
{
if ($id > 0 || $ref) {
$head = prelevement_prepare_head($object);
print dol_get_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
if (GETPOST('error', 'alpha') != '')
{
if (GETPOST('error', 'alpha') != '') {
print '<div class="error">'.$object->getErrorString(GETPOST('error', 'alpha')).'</div>';
}
@ -210,8 +209,7 @@ if ($id > 0 || $ref)
print '</tr>';
*/
if ($object->date_trans <> 0)
{
if ($object->date_trans <> 0) {
$muser = new User($db);
$muser->fetch($object->user_trans);
@ -222,8 +220,7 @@ if ($id > 0 || $ref)
print $object->methodes_trans[$object->method_trans];
print '</td></tr>';
}
if ($object->date_credit <> 0)
{
if ($object->date_credit <> 0) {
print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
print dol_print_date($object->date_credit, 'day');
print '</td></tr>';
@ -241,22 +238,29 @@ if ($id > 0 || $ref)
print '<tr><td class="titlefield">';
$labelofbankfield = "BankToReceiveWithdraw";
if ($object->type == 'bank-transfer') $labelofbankfield = 'BankToPayCreditTransfer';
if ($object->type == 'bank-transfer') {
$labelofbankfield = 'BankToPayCreditTransfer';
}
print $langs->trans($labelofbankfield);
print '</td>';
print '<td>';
if ($acc->id > 0)
if ($acc->id > 0) {
print $acc->getNomUrl(1);
}
print '</td>';
print '</tr>';
print '<tr><td class="titlefield">';
$labelfororderfield = 'WithdrawalFile';
if ($object->type == 'bank-transfer') $labelfororderfield = 'CreditTransferFile';
if ($object->type == 'bank-transfer') {
$labelfororderfield = 'CreditTransferFile';
}
print $langs->trans($labelfororderfield).'</td><td>';
$relativepath = 'receipts/'.$object->ref.'.xml';
$modulepart = 'prelevement';
if ($object->type == 'bank-transfer') $modulepart = 'paymentbybanktransfer';
if ($object->type == 'bank-transfer') {
$modulepart = 'paymentbybanktransfer';
}
print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath.'</a>';
print '</td></tr></table>';
@ -268,8 +272,7 @@ if ($id > 0 || $ref)
$formconfirm = '';
// Confirmation to delete
if ($action == 'delete')
{
if ($action == 'delete') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Delete'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
}
@ -283,8 +286,7 @@ if ($id > 0 || $ref)
print $formconfirm;
if (empty($object->date_trans) && $user->rights->prelevement->bons->send && $action == 'settransmitted')
{
if (empty($object->date_trans) && $user->rights->prelevement->bons->send && $action == 'settransmitted') {
print '<form method="post" name="userfile" action="card.php?id='.$object->id.'" enctype="multipart/form-data">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="infotrans">';
@ -303,8 +305,7 @@ if ($id > 0 || $ref)
print '<br>';
}
if (!empty($object->date_trans) && $object->date_credit == 0 && $user->rights->prelevement->bons->credit && $action == 'setcredited')
{
if (!empty($object->date_trans) && $object->date_credit == 0 && $user->rights->prelevement->bons->credit && $action == 'setcredited') {
print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="infocredit">';
@ -323,17 +324,14 @@ if ($id > 0 || $ref)
// Actions
if ($action != 'settransmitted' && $action != 'setcredited')
{
if ($action != 'settransmitted' && $action != 'setcredited') {
print "\n<div class=\"tabsAction\">\n";
if (empty($object->date_trans) && $user->rights->prelevement->bons->send)
{
if (empty($object->date_trans) && $user->rights->prelevement->bons->send) {
print "<a class=\"butAction\" href=\"card.php?action=settransmitted&token='.newToken().'&id=".$object->id."\">".$langs->trans("SetToStatusSent")."</a>";
}
if (!empty($object->date_trans) && $object->date_credit == 0)
{
if (!empty($object->date_trans) && $object->date_credit == 0) {
print "<a class=\"butAction\" href=\"card.php?action=setcredited&token='.newToken().'&id=".$object->id."\">".$langs->trans("ClassCredited")."</a>";
}
@ -357,13 +355,14 @@ if ($id > 0 || $ref)
$sql .= " AND pl.fk_prelevement_bons = pb.rowid";
$sql .= " AND pb.entity = ".$conf->entity;
$sql .= " AND pl.fk_soc = s.rowid";
if ($socid) $sql .= " AND s.rowid = ".$socid;
if ($socid) {
$sql .= " AND s.rowid = ".$socid;
}
$sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) {
@ -377,8 +376,7 @@ if ($id > 0 || $ref)
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
@ -406,8 +404,7 @@ if ($id > 0 || $ref)
$total = 0;
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($result);
print '<tr class="oddeven">';
@ -430,15 +427,12 @@ if ($id > 0 || $ref)
print '<td class="right">';
if ($obj->statut == 3)
{
print '<b>'.$langs->trans("StatusRefused").'</b>';
if ($obj->statut == 3) {
print '<b>'.$langs->trans("StatusRefused").'</b>';
} else {
if ($object->statut == BonPrelevement::STATUS_CREDITED)
{
if ($object->statut == BonPrelevement::STATUS_CREDITED) {
if ($obj->statut == 2) {
if ($user->rights->prelevement->bons->credit)
{
if ($user->rights->prelevement->bons->credit) {
//print '<a class="butActionDelete" href="line.php?action=rejet&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>';
print '<a href="line.php?action=rejet&type='.$object->type.'&id='.$obj->rowid.'">'.$langs->trans("StandingOrderReject").'</a>';
} else {
@ -464,7 +458,9 @@ if ($id > 0 || $ref)
print '<td class="right">';
if (empty($offset) && $num <= $limit) {
// If we have all record on same page, then the following test/warning can be done
if ($total != $object->amount) print img_warning($langs->trans("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines"));
if ($total != $object->amount) {
print img_warning($langs->trans("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines"));
}
}
print price($total);
print "</td>\n";

View File

@ -144,10 +144,8 @@ class BonPrelevement extends CommonObject
// Add lines
$result = $this->addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key);
if ($result == 0)
{
if ($line_id > 0)
{
if ($result == 0) {
if ($line_id > 0) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_facture (";
if ($type != 'bank-transfer') {
$sql .= "fk_facture";
@ -160,8 +158,7 @@ class BonPrelevement extends CommonObject
$sql .= ", ".$line_id;
$sql .= ")";
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$result = 0;
} else {
$result = -1;
@ -199,8 +196,7 @@ class BonPrelevement extends CommonObject
$result = -1;
$concat = 0;
if ($concat == 1)
{
if ($concat == 1) {
/*
* We aggregate the lines
*/
@ -213,8 +209,7 @@ class BonPrelevement extends CommonObject
$sql .= " AND number = '".$this->db->escape($number)."'";
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
} else {
$result = -1;
@ -243,8 +238,7 @@ class BonPrelevement extends CommonObject
$sql .= ", '".$this->db->escape($number_key)."'";
$sql .= ")";
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_lignes");
$result = 0;
} else {
@ -295,15 +289,16 @@ class BonPrelevement extends CommonObject
$sql .= ", p.statut as status";
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
$sql .= " WHERE p.entity IN (".getEntity('invoice').")";
if ($rowid > 0) $sql .= " AND p.rowid = ".$rowid;
else $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
if ($rowid > 0) {
$sql .= " AND p.rowid = ".$rowid;
} else {
$sql .= " AND p.ref = '".$this->db->escape($ref)."'";
}
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
if ($result) {
if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
@ -349,28 +344,24 @@ class BonPrelevement extends CommonObject
$error = 0;
if ($this->db->begin())
{
if ($this->db->begin()) {
$sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons";
$sql .= " SET statut = ".self::STATUS_TRANSFERED;
$sql .= " WHERE rowid = ".$this->id;
$sql .= " AND entity = ".$conf->entity;
$result = $this->db->query($sql);
if (!$result)
{
if (!$result) {
dol_syslog(get_class($this)."::set_credite Erreur 1");
$error++;
}
if (!$error)
{
if (!$error) {
$facs = array();
$facs = $this->getListInvoices();
$num = count($facs);
for ($i = 0; $i < $num; $i++)
{
for ($i = 0; $i < $num; $i++) {
/* Tag invoice as paid */
dol_syslog(get_class($this)."::set_credite set_paid fac ".$facs[$i]);
$fac = new Facture($this->db);
@ -379,14 +370,12 @@ class BonPrelevement extends CommonObject
}
}
if (!$error)
{
if (!$error) {
$sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes";
$sql .= " SET statut = 2";
$sql .= " WHERE fk_prelevement_bons = ".$this->id;
if (!$this->db->query($sql))
{
if (!$this->db->query($sql)) {
dol_syslog(get_class($this)."::set_credite Erreur 1");
$error++;
}
@ -395,8 +384,7 @@ class BonPrelevement extends CommonObject
/*
* End of procedure
*/
if (!$error)
{
if (!$error) {
$this->db->commit();
return 0;
} else {
@ -426,10 +414,8 @@ class BonPrelevement extends CommonObject
$error = 0;
if ($this->fetched == 1)
{
if ($date < $this->date_trans)
{
if ($this->fetched == 1) {
if ($date < $this->date_trans) {
$this->error = 'DateOfMovementLowerThanDateOfFileTransmission';
dol_syslog("bon-prelevment::set_infocredit 1027 ".$this->error);
return -1027;
@ -446,8 +432,7 @@ class BonPrelevement extends CommonObject
$sql .= " AND statut = ".self::STATUS_TRANSFERED;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$langs->load('withdrawals');
$subject = $langs->trans("InfoCreditSubject", $this->ref);
$message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date, 'dayhour'));
@ -462,8 +447,7 @@ class BonPrelevement extends CommonObject
// Loop on each invoice. $facs=array(0=>id, 1=>amount requested)
$num = count($facs);
for ($i = 0; $i < $num; $i++)
{
for ($i = 0; $i < $num; $i++) {
if ($this->type == 'bank-transfer') {
$fac = new FactureFournisseur($this->db);
} else {
@ -492,8 +476,7 @@ class BonPrelevement extends CommonObject
//var_dump($amountsperthirdparty);exit;
// Make one payment per customer
foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts)
{
foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) {
if ($this->type == 'bank-transfer') {
$paiement = new PaiementFourn($this->db);
} else {
@ -514,8 +497,7 @@ class BonPrelevement extends CommonObject
$paiement->id_prelevement = $this->id;
$paiement_id = $paiement->create($user); // This use ->paiementid, that is ID of payment mode
if ($paiement_id < 0)
{
if ($paiement_id < 0) {
$error++;
$this->error = $paiement->error;
$this->errors = $paiement->errors;
@ -528,8 +510,7 @@ class BonPrelevement extends CommonObject
}
$result = $paiement->addPaymentToBank($user, $modeforaddpayment, '(WithdrawalPayment)', $bankaccount, '', '');
if ($result < 0)
{
if ($result < 0) {
$error++;
$this->error = $paiement->error;
$this->errors = $paiement->errors;
@ -562,8 +543,7 @@ class BonPrelevement extends CommonObject
/*
* End of procedure
*/
if ($error == 0)
{
if ($error == 0) {
$this->date_credit = $date;
$this->statut = self::STATUS_CREDITED;
@ -595,8 +575,7 @@ class BonPrelevement extends CommonObject
$error = 0;
dol_syslog(get_class($this)."::set_infotrans Start", LOG_INFO);
if ($this->db->begin())
{
if ($this->db->begin()) {
$sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons ";
$sql .= " SET fk_user_trans = ".$user->id;
$sql .= " , date_trans = '".$this->db->idate($date)."'";
@ -606,8 +585,7 @@ class BonPrelevement extends CommonObject
$sql .= " AND entity = ".$conf->entity;
$sql .= " AND statut = 0";
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$this->method_trans = $method;
$langs->load('withdrawals');
$subject = $langs->trans("InfoTransSubject", $this->ref);
@ -619,8 +597,7 @@ class BonPrelevement extends CommonObject
$error++;
}
if ($error == 0)
{
if ($error == 0) {
$this->date_trans = $date;
$this->statut = 1;
$this->user_trans = $user->id;
@ -660,7 +637,9 @@ class BonPrelevement extends CommonObject
} else {
$sql .= " pf.fk_facture";
}
if ($amounts) $sql .= ", SUM(pl.amount)";
if ($amounts) {
$sql .= ", SUM(pl.amount)";
}
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
$sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
$sql .= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
@ -677,18 +656,16 @@ class BonPrelevement extends CommonObject
}
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num)
{
if ($num) {
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $this->db->fetch_row($resql);
if (!$amounts) $arr[$i] = $row[0];
else {
if (!$amounts) {
$arr[$i] = $row[0];
} else {
$arr[$i] = array(
$row[0],
$row[1]
@ -725,8 +702,7 @@ class BonPrelevement extends CommonObject
}
$sql .= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
$sql .= " WHERE f.entity IN (".getEntity('invoice').")";
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS))
{
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
$sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
}
if ($mode != 'bank-transfer') {
@ -740,8 +716,7 @@ class BonPrelevement extends CommonObject
$sql .= " AND f.total_ttc > 0";
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $this->db->fetch_object($resql);
$this->db->free($resql);
@ -787,8 +762,7 @@ class BonPrelevement extends CommonObject
}
$sql .= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
$sql .= " WHERE f.entity IN (".getEntity('invoice').")";
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS))
{
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
$sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
}
if ($type == 'bank-transfer') {
@ -803,8 +777,7 @@ class BonPrelevement extends CommonObject
dol_syslog(get_class($this)."::NbFactureAPrelever");
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $this->db->fetch_object($resql);
$this->db->free($resql);
@ -852,7 +825,9 @@ class BonPrelevement extends CommonObject
$datetimeprev = time();
//Choice the date of the execution direct debit
if (!empty($executiondate)) $datetimeprev = $executiondate;
if (!empty($executiondate)) {
$datetimeprev = $executiondate;
}
$month = strftime("%m", $datetimeprev);
$year = strftime("%Y", $datetimeprev);
@ -867,8 +842,7 @@ class BonPrelevement extends CommonObject
$factures_prev_id = array();
$factures_errors = array();
if (!$error)
{
if (!$error) {
$sql = "SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc";
$sql .= ", pfd.code_banque, pfd.code_guichet, pfd.number, pfd.cle_rib";
$sql .= ", pfd.amount";
@ -896,13 +870,11 @@ class BonPrelevement extends CommonObject
dol_syslog(__METHOD__."::Read invoices, sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $this->db->fetch_row($resql);
$factures[$i] = $row; // All fields
if ($row[7] == 0) {
@ -921,8 +893,7 @@ class BonPrelevement extends CommonObject
}
}
if (!$error)
{
if (!$error) {
require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
$soc = new Societe($this->db);
@ -930,36 +901,29 @@ class BonPrelevement extends CommonObject
$i = 0;
dol_syslog(__METHOD__."::Check BAN", LOG_DEBUG);
if (count($factures) > 0)
{
foreach ($factures as $key => $fac)
{
if (count($factures) > 0) {
foreach ($factures as $key => $fac) {
if ($type != 'bank-transfer') {
$tmpinvoice = new Facture($this->db);
} else {
$tmpinvoice = new FactureFournisseur($this->db);
}
$resfetch = $tmpinvoice->fetch($fac[0]);
if ($resfetch >= 0) // Field 0 of $fac is rowid of invoice
{
if ($soc->fetch($tmpinvoice->socid) >= 0)
{
if ($resfetch >= 0) { // Field 0 of $fac is rowid of invoice
if ($soc->fetch($tmpinvoice->socid) >= 0) {
$bac = new CompanyBankAccount($this->db);
$bac->fetch(0, $soc->id);
if ($type != 'bank-transfer') {
if ($format == 'FRST' && $bac->frstrecur != 'FRST')
{
if ($format == 'FRST' && $bac->frstrecur != 'FRST') {
continue;
}
if ($format == 'RCUR' && ($bac->frstrecur != 'RCUR' && $bac->frstrecur != 'RECUR'))
{
if ($format == 'RCUR' && ($bac->frstrecur != 'RCUR' && $bac->frstrecur != 'RECUR')) {
continue;
}
}
if ($bac->verif() >= 1)
{
if ($bac->verif() >= 1) {
$factures_prev[$i] = $fac;
/* second array necessary for BonPrelevement */
$factures_prev_id[$i] = $fac[0];
@ -998,8 +962,7 @@ class BonPrelevement extends CommonObject
$i++;
}*/
if (count($factures_prev) > 0)
{
if (count($factures_prev) > 0) {
if ($mode == 'real') {
$ok = 1;
} else {
@ -1007,8 +970,7 @@ class BonPrelevement extends CommonObject
}
}
if ($ok)
{
if ($ok) {
/*
* We are in real mode.
* We create order and build file into disk
@ -1020,8 +982,7 @@ class BonPrelevement extends CommonObject
/*
* Process order generation
*/
if (!$error)
{
if (!$error) {
$ref = substr($year, -2).$month;
$sql = "SELECT substring(ref from char_length(ref) - 1)";
@ -1033,8 +994,7 @@ class BonPrelevement extends CommonObject
dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$row = $this->db->fetch_row($resql);
$ref = "T".$ref.str_pad(dol_substr("00".intval($row[0]) + 1, 0, 2), 2, "0", STR_PAD_LEFT);
@ -1043,7 +1003,9 @@ class BonPrelevement extends CommonObject
} else {
$dir = $conf->paymentbybanktransfer->dir_output.'/receipts';
}
if (!is_dir($dir)) dol_mkdir($dir);
if (!is_dir($dir)) {
dol_mkdir($dir);
}
$this->filename = $dir.'/'.$ref.'.xml';
@ -1058,8 +1020,7 @@ class BonPrelevement extends CommonObject
$sql .= ")";
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons");
$this->id = $prev_id;
$this->ref = $ref;
@ -1073,8 +1034,7 @@ class BonPrelevement extends CommonObject
}
}
if (!$error)
{
if (!$error) {
if ($type != 'bank-transfer') {
$fact = new Facture($this->db);
} else {
@ -1084,10 +1044,8 @@ class BonPrelevement extends CommonObject
/*
* Create withdrawal receipt in database
*/
if (count($factures_prev) > 0)
{
foreach ($factures_prev as $fac) // Add a link in database for each invoice
{
if (count($factures_prev) > 0) {
foreach ($factures_prev as $fac) { // Add a link in database for each invoice
// Fetch invoice
$result = $fact->fetch($fac[0]);
if ($result < 0) {
@ -1109,8 +1067,7 @@ class BonPrelevement extends CommonObject
* $fac[8] : client nom
*/
$ri = $this->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type);
if ($ri <> 0)
{
if ($ri <> 0) {
$error++;
}
@ -1122,8 +1079,7 @@ class BonPrelevement extends CommonObject
$sql .= " WHERE rowid = ".$fac[1];
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$error++;
$this->errors[] = $this->db->lasterror();
dol_syslog(__METHOD__."::Update Error=".$this->db->lasterror(), LOG_ERR);
@ -1132,16 +1088,14 @@ class BonPrelevement extends CommonObject
}
}
if (!$error)
{
if (!$error) {
/*
* Create file of type='direct-debit' for direct debit order or type='bank-transfer' for credit transfer into a XML file
*/
dol_syslog(__METHOD__."::Init direct debit or credit transfer file for ".count($factures_prev)." invoices", LOG_DEBUG);
if (count($factures_prev) > 0)
{
if (count($factures_prev) > 0) {
$this->date_echeance = $datetimeprev;
$this->reference_remise = $ref;
@ -1150,8 +1104,7 @@ class BonPrelevement extends CommonObject
$id = $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT;
}
$account = new Account($this->db);
if ($account->fetch($id) > 0)
{
if ($account->fetch($id) > 0) {
$this->emetteur_code_banque = $account->code_banque;
$this->emetteur_code_guichet = $account->code_guichet;
$this->emetteur_numero_compte = $account->number;
@ -1190,15 +1143,13 @@ class BonPrelevement extends CommonObject
$sql .= " AND entity = ".$conf->entity;
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$error++;
dol_syslog(__METHOD__."::Error update total: ".$this->db->error(), LOG_ERR);
}
}
if (!$error && !$notrigger)
{
if (!$error && !$notrigger) {
$triggername = 'DIRECT_DEBIT_ORDER_CREATE';
if ($type != 'bank-transfer') {
$triggername = 'CREDIT_TRANSFER_ORDER_CREATE';
@ -1206,12 +1157,13 @@ class BonPrelevement extends CommonObject
// Call trigger
$result = $this->call_trigger($triggername, $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
// End call triggers
}
if (!$error)
{
if (!$error) {
$this->db->commit();
return count($factures_prev);
} else {
@ -1238,48 +1190,52 @@ class BonPrelevement extends CommonObject
$error = 0;
$resql1 = $resql2 = $resql3 = $resql4 = 0;
if (!$notrigger)
{
if (!$notrigger) {
$triggername = 'DIRECT_DEBIT_ORDER_DELETE';
if ($this->type == 'bank-transfer') {
$triggername = 'PAYMENTBYBANKTRANFER_DELETE';
}
// Call trigger
$result = $this->call_trigger($triggername, $user);
if ($result < 0) $error++;
if ($result < 0) {
$error++;
}
// End call triggers
}
if (!$error)
{
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."prelevement_facture WHERE fk_prelevement_lignes IN (SELECT rowid FROM ".MAIN_DB_PREFIX."prelevement_lignes WHERE fk_prelevement_bons = ".$this->id.")";
$resql1 = $this->db->query($sql);
if (!$resql1) dol_print_error($this->db);
if (!$resql1) {
dol_print_error($this->db);
}
}
if (!$error)
{
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."prelevement_lignes WHERE fk_prelevement_bons = ".$this->id;
$resql2 = $this->db->query($sql);
if (!$resql2) dol_print_error($this->db);
if (!$resql2) {
dol_print_error($this->db);
}
}
if (!$error)
{
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."prelevement_bons WHERE rowid = ".$this->id;
$resql3 = $this->db->query($sql);
if (!$resql3) dol_print_error($this->db);
if (!$resql3) {
dol_print_error($this->db);
}
}
if (!$error)
{
if (!$error) {
$sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = ".$this->id;
$resql4 = $this->db->query($sql);
if (!$resql4) dol_print_error($this->db);
if (!$resql4) {
dol_print_error($this->db);
}
}
if ($resql1 && $resql2 && $resql3 && $resql4 && !$error)
{
if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
$this->db->commit();
return 1;
} else {
@ -1303,7 +1259,9 @@ class BonPrelevement extends CommonObject
{
global $conf, $langs, $hookmanager;
if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
if (!empty($conf->dol_no_mouse_hover)) {
$notooltip = 1; // Force disable tooltips
}
$result = '';
@ -1324,19 +1282,20 @@ class BonPrelevement extends CommonObject
$url = DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$this->id;
}
if ($option != 'nolink')
{
if ($option != 'nolink') {
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
$add_save_lastsearch_values = 1;
}
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
}
$linkclose = '';
if (empty($notooltip))
{
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
{
if (empty($notooltip)) {
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$label = $langs->trans("ShowMyObject");
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
}
@ -1349,15 +1308,21 @@ class BonPrelevement extends CommonObject
$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $linkclose = $hookmanager->resPrint;
*/
} else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
} else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
$linkstart = '<a href="'.$url.'"';
$linkstart .= $linkclose.'>';
$linkend = '</a>';
$result .= $linkstart;
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
if ($withpicto != 2) $result .= $this->ref;
if ($withpicto) {
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
}
if ($withpicto != 2) {
$result .= $this->ref;
}
$result .= $linkend;
//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
@ -1365,8 +1330,11 @@ class BonPrelevement extends CommonObject
$hookmanager->initHooks(array('banktransferdao'));
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) $result = $hookmanager->resPrint;
else $result .= $hookmanager->resPrint;
if ($reshook > 0) {
$result = $hookmanager->resPrint;
} else {
$result .= $hookmanager->resPrint;
}
return $result;
}
@ -1387,8 +1355,7 @@ class BonPrelevement extends CommonObject
$sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def";
$sql .= " WHERE rowid = ".((int) $rowid);
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
return 0;
} else {
return -1;
@ -1411,8 +1378,7 @@ class BonPrelevement extends CommonObject
$sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def";
$sql .= " WHERE fk_user=".$user." AND fk_action='".$this->db->escape($action)."'";
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
return 0;
} else {
return -1;
@ -1433,16 +1399,14 @@ class BonPrelevement extends CommonObject
// phpcs:enable
$result = 0;
if ($this->DeleteNotification($user, $action) == 0)
{
if ($this->DeleteNotification($user, $action) == 0) {
$now = dol_now();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
$sql .= " VALUES ('".$this->db->idate($now)."', ".$user.", 'NULL', 'NULL', '".$this->db->escape($action)."')";
dol_syslog("adnotiff: ".$sql);
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$result = 0;
} else {
$result = -1;
@ -1477,8 +1441,7 @@ class BonPrelevement extends CommonObject
dol_syslog(get_class($this)."::generate build file=".$this->filename." type=".$type);
$this->file = fopen($this->filename, "w");
if (empty($this->file))
{
if (empty($this->file)) {
$this->error = $langs->trans('ErrorFailedToOpenFile', $this->filename);
return -1;
}
@ -1487,8 +1450,7 @@ class BonPrelevement extends CommonObject
$this->total = 0;
// Build file for European countries
if ($mysoc->isInEEC())
{
if ($mysoc->isInEEC()) {
$found++;
if ($type != 'bank-transfer') {
@ -1503,7 +1465,9 @@ class BonPrelevement extends CommonObject
$dateTime_ECMA = dol_print_date($now, '%Y-%m-%dT%H:%M:%S');
$date_actu = $now;
if (!empty($executiondate)) $date_actu = $executiondate;
if (!empty($executiondate)) {
$date_actu = $executiondate;
}
$dateTime_YMD = dol_print_date($date_actu, '%Y%m%d');
$dateTime_YMDHMS = dol_print_date($date_actu, '%Y%m%d%H%M%S');
@ -1537,13 +1501,11 @@ class BonPrelevement extends CommonObject
// Define $fileDebiteurSection. One section DrctDbtTxInf per invoice.
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$cachearraytotestduplicate = array();
$num = $this->db->num_rows($resql);
while ($i < $num)
{
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
if (!empty($cachearraytotestduplicate[$obj->idfac])) {
@ -1567,8 +1529,7 @@ class BonPrelevement extends CommonObject
}
// Define $fileEmetteurSection. Start of bloc PmtInf. Will contains all $nbtotalDrctDbtTxInf
if ($result != -2)
{
if ($result != -2) {
$fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
}
@ -1597,11 +1558,13 @@ class BonPrelevement extends CommonObject
fputs($this->file, ' </InitgPty>'.$CrLf);
fputs($this->file, ' </GrpHdr>'.$CrLf);
// SEPA File Emetteur
if ($result != -2)
{ fputs($this-> file, $fileEmetteurSection); }
if ($result != -2) {
fputs($this-> file, $fileEmetteurSection);
}
// SEPA File Debiteurs
if ($result != -2)
{ fputs($this-> file, $fileDebiteurSection); }
if ($result != -2) {
fputs($this-> file, $fileDebiteurSection);
}
// SEPA FILE FOOTER
fputs($this->file, ' </PmtInf>'.$CrLf);
fputs($this->file, ' </CstmrDrctDbtInitn>'.$CrLf);
@ -1618,7 +1581,9 @@ class BonPrelevement extends CommonObject
$dateTime_ECMA = dol_print_date($now, '%Y-%m-%dT%H:%M:%S');
$date_actu = $now;
if (!empty($executiondate)) $date_actu = $executiondate;
if (!empty($executiondate)) {
$date_actu = $executiondate;
}
$dateTime_YMD = dol_print_date($date_actu, '%Y%m%d');
$dateTime_YMDHMS = dol_print_date($date_actu, '%Y%m%d%H%M%S');
@ -1652,13 +1617,11 @@ class BonPrelevement extends CommonObject
// Define $fileCrediteurSection. One section DrctDbtTxInf per invoice.
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$cachearraytotestduplicate = array();
$num = $this->db->num_rows($resql);
while ($i < $num)
{
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
if (!empty($cachearraytotestduplicate[$obj->idfac])) {
@ -1711,11 +1674,13 @@ class BonPrelevement extends CommonObject
fputs($this->file, ' </InitgPty>'.$CrLf);
fputs($this->file, ' </GrpHdr>'.$CrLf);
// SEPA File Emetteur (mycompany)
if ($result != -2)
{ fputs($this-> file, $fileEmetteurSection); }
if ($result != -2) {
fputs($this-> file, $fileEmetteurSection);
}
// SEPA File Creditors
if ($result != -2)
{ fputs($this-> file, $fileCrediteurSection); }
if ($result != -2) {
fputs($this-> file, $fileCrediteurSection);
}
// SEPA FILE FOOTER
fputs($this->file, ' </PmtInf>'.$CrLf);
fputs($this->file, ' </CstmrCdtTrfInitn>'.$CrLf);
@ -1724,8 +1689,7 @@ class BonPrelevement extends CommonObject
}
// Build file for Other Countries with unknow format
if (!$found)
{
if (!$found) {
if ($type != 'bank-transfer') {
$sql = "SELECT pl.amount";
$sql .= " FROM";
@ -1739,12 +1703,10 @@ class BonPrelevement extends CommonObject
// Lines
$i = 0;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
while ($i < $num)
{
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$this->total = $this->total + $obj->amount;
@ -1767,12 +1729,10 @@ class BonPrelevement extends CommonObject
// Lines
$i = 0;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
while ($i < $num)
{
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
$this->total = $this->total + $obj->amount;
@ -1958,8 +1918,12 @@ class BonPrelevement extends CommonObject
$XML_DEBITOR .= ' <Ctry>'.$row_country_code.'</Ctry>'.$CrLf;
$addressline1 = dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => "")));
$addressline2 = dol_string_unaccent(strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => "")));
if (trim($addressline1)) $XML_DEBITOR .= ' <AdrLine>'.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', true)).'</AdrLine>'.$CrLf;
if (trim($addressline2)) $XML_DEBITOR .= ' <AdrLine>'.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', true)).'</AdrLine>'.$CrLf;
if (trim($addressline1)) {
$XML_DEBITOR .= ' <AdrLine>'.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', true)).'</AdrLine>'.$CrLf;
}
if (trim($addressline2)) {
$XML_DEBITOR .= ' <AdrLine>'.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', true)).'</AdrLine>'.$CrLf;
}
$XML_DEBITOR .= ' </PstlAdr>'.$CrLf;
$XML_DEBITOR .= ' </Dbtr>'.$CrLf;
$XML_DEBITOR .= ' <DbtrAcct>'.$CrLf;
@ -2005,8 +1969,12 @@ class BonPrelevement extends CommonObject
$XML_CREDITOR .= ' <Ctry>'.$row_country_code.'</Ctry>'.$CrLf;
$addressline1 = dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => "")));
$addressline2 = dol_string_unaccent(strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => "")));
if (trim($addressline1)) $XML_CREDITOR .= ' <AdrLine>'.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', true)).'</AdrLine>'.$CrLf;
if (trim($addressline2)) $XML_CREDITOR .= ' <AdrLine>'.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', true)).'</AdrLine>'.$CrLf;
if (trim($addressline1)) {
$XML_CREDITOR .= ' <AdrLine>'.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', true)).'</AdrLine>'.$CrLf;
}
if (trim($addressline2)) {
$XML_CREDITOR .= ' <AdrLine>'.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', true)).'</AdrLine>'.$CrLf;
}
$XML_CREDITOR .= ' </PstlAdr>'.$CrLf;
$XML_CREDITOR .= ' </Cdtr>'.$CrLf;
$XML_CREDITOR .= ' <CdtrAcct>'.$CrLf;
@ -2122,8 +2090,7 @@ class BonPrelevement extends CommonObject
//$id = $configuration->global->PRELEVEMENT_ID_BANKACCOUNT;
$id = ($type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
$account = new Account($this->db);
if ($account->fetch($id) > 0)
{
if ($account->fetch($id) > 0) {
$this->emetteur_code_banque = $account->code_banque;
$this->emetteur_code_guichet = $account->code_guichet;
$this->emetteur_numero_compte = $account->number;
@ -2143,8 +2110,7 @@ class BonPrelevement extends CommonObject
$sql .= " WHERE pb.rowid = ".$this->id;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $this->db->fetch_object($resql);
$country = explode(':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY);
@ -2175,8 +2141,12 @@ class BonPrelevement extends CommonObject
$XML_SEPA_INFO .= ' <Ctry>'.$country[1].'</Ctry>'.$CrLf;
$addressline1 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => "")));
$addressline2 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP.(($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' '.$configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '').$configuration->global->MAIN_INFO_SOCIETE_TOWN, array(CHR(13) => ", ", CHR(10) => "")));
if ($addressline1) $XML_SEPA_INFO .= ' <AdrLine>'.$addressline1.'</AdrLine>'.$CrLf;
if ($addressline2) $XML_SEPA_INFO .= ' <AdrLine>'.$addressline2.'</AdrLine>'.$CrLf;
if ($addressline1) {
$XML_SEPA_INFO .= ' <AdrLine>'.$addressline1.'</AdrLine>'.$CrLf;
}
if ($addressline2) {
$XML_SEPA_INFO .= ' <AdrLine>'.$addressline2.'</AdrLine>'.$CrLf;
}
$XML_SEPA_INFO .= ' </PstlAdr>'.$CrLf;
$XML_SEPA_INFO .= ' </Cdtr>'.$CrLf;
$XML_SEPA_INFO .= ' <CdtrAcct>'.$CrLf;
@ -2237,8 +2207,12 @@ class BonPrelevement extends CommonObject
$XML_SEPA_INFO .= ' <Ctry>'.$country[1].'</Ctry>'.$CrLf;
$addressline1 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => "")));
$addressline2 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP.(($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' '.$configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '').$configuration->global->MAIN_INFO_SOCIETE_TOWN, array(CHR(13) => ", ", CHR(10) => "")));
if ($addressline1) $XML_SEPA_INFO .= ' <AdrLine>'.$addressline1.'</AdrLine>'.$CrLf;
if ($addressline2) $XML_SEPA_INFO .= ' <AdrLine>'.$addressline2.'</AdrLine>'.$CrLf;
if ($addressline1) {
$XML_SEPA_INFO .= ' <AdrLine>'.$addressline1.'</AdrLine>'.$CrLf;
}
if ($addressline2) {
$XML_SEPA_INFO .= ' <AdrLine>'.$addressline2.'</AdrLine>'.$CrLf;
}
$XML_SEPA_INFO .= ' </PstlAdr>'.$CrLf;
$XML_SEPA_INFO .= ' </Dbtr>'.$CrLf;
$XML_SEPA_INFO .= ' <DbtrAcct>'.$CrLf;
@ -2364,8 +2338,7 @@ class BonPrelevement extends CommonObject
public function LibStatut($status, $mode = 0)
{
// phpcs:enable
if (empty($this->labelStatus) || empty($this->labelStatusShort))
{
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;
//$langs->load("mymodule");
$this->labelStatus[self::STATUS_DRAFT] = $langs->trans('StatusWaiting');
@ -2377,8 +2350,12 @@ class BonPrelevement extends CommonObject
}
$statusType = 'status1';
if ($status == self::STATUS_TRANSFERED) $statusType = 'status3';
if ($status == self::STATUS_CREDITED) $statusType = 'status6';
if ($status == self::STATUS_TRANSFERED) {
$statusType = 'status3';
}
if ($status == self::STATUS_CREDITED) {
$statusType = 'status6';
}
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}

View File

@ -84,10 +84,8 @@ class LignePrelevement
$sql .= " AND p.entity = ".$conf->entity;
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@ -135,24 +133,32 @@ class LignePrelevement
// phpcs:enable
global $langs;
if ($mode == 0)
{
if ($mode == 0) {
return $langs->trans($this->statuts[$status]);
} elseif ($mode == 1)
{
if ($status == 0) return img_picto($langs->trans($this->statuts[$status]), 'statut1').' '.$langs->trans($this->statuts[$status]); // Waiting
elseif ($status == 2) return img_picto($langs->trans($this->statuts[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]); // Credited
elseif ($status == 3) return img_picto($langs->trans($this->statuts[$status]), 'statut8').' '.$langs->trans($this->statuts[$status]); // Refused
} elseif ($mode == 2)
{
if ($status == 0) return img_picto($langs->trans($this->statuts[$status]), 'statut1');
elseif ($status == 2) return img_picto($langs->trans($this->statuts[$status]), 'statut6');
elseif ($status == 3) return img_picto($langs->trans($this->statuts[$status]), 'statut8');
} elseif ($mode == 3)
{
if ($status == 0) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut1');
elseif ($status == 2) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut6');
elseif ($status == 3) return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut8');
} elseif ($mode == 1) {
if ($status == 0) {
return img_picto($langs->trans($this->statuts[$status]), 'statut1').' '.$langs->trans($this->statuts[$status]); // Waiting
} elseif ($status == 2) {
return img_picto($langs->trans($this->statuts[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]); // Credited
} elseif ($status == 3) {
return img_picto($langs->trans($this->statuts[$status]), 'statut8').' '.$langs->trans($this->statuts[$status]); // Refused
}
} elseif ($mode == 2) {
if ($status == 0) {
return img_picto($langs->trans($this->statuts[$status]), 'statut1');
} elseif ($status == 2) {
return img_picto($langs->trans($this->statuts[$status]), 'statut6');
} elseif ($status == 3) {
return img_picto($langs->trans($this->statuts[$status]), 'statut8');
}
} elseif ($mode == 3) {
if ($status == 0) {
return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut1');
} elseif ($status == 2) {
return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut6');
} elseif ($status == 3) {
return $langs->trans($this->statuts[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut8');
}
}
}

View File

@ -119,8 +119,7 @@ class RejetPrelevement
$result = $this->db->query($sql);
if (!$result)
{
if (!$result) {
dol_syslog("RejetPrelevement::create Erreur 4");
dol_syslog("RejetPrelevement::create Erreur 4 $sql");
$error++;
@ -131,8 +130,7 @@ class RejetPrelevement
$sql .= " SET statut = 3";
$sql .= " WHERE rowid = ".$id;
if (!$this->db->query($sql))
{
if (!$this->db->query($sql)) {
dol_syslog("RejetPrelevement::create Erreur 5");
$error++;
}
@ -191,8 +189,7 @@ class RejetPrelevement
$this->_send_email($fac);
}
if ($error == 0)
{
if ($error == 0) {
dol_syslog("RejetPrelevement::Create Commit");
$this->db->commit();
} else {
@ -221,11 +218,9 @@ class RejetPrelevement
$sql .= " AND pfd.fk_facture".($this->type == 'bank-transfer' ? '_fourn=' : '=').$fac->id;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num > 0)
{
if ($num > 0) {
$row = $this->db->fetch_row($resql);
$userid = $row[0];
}
@ -233,8 +228,7 @@ class RejetPrelevement
dol_syslog("RejetPrelevement::_send_email Erreur lecture user");
}
if ($userid > 0)
{
if ($userid > 0) {
$emuser = new User($this->db);
$emuser->fetch($userid);
@ -288,22 +282,22 @@ class RejetPrelevement
//Returns all invoices of a withdrawal
$sql = "SELECT f.rowid as facid, pl.amount";
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture as pf";
if ($this->type == 'bank-transfer') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)";
else $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)";
if ($this->type == 'bank-transfer') {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON (pf.fk_facture_fourn = f.rowid)";
} else {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)";
}
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)";
$sql .= " WHERE pf.fk_prelevement_lignes = ".$this->id;
$sql .= " AND f.entity IN (".getEntity('invoice').")";
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num)
{
if ($num) {
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$row = $this->db->fetch_row($resql);
if (!$amounts) {
$arr[$i] = $row[0];
@ -338,10 +332,8 @@ class RejetPrelevement
$sql .= " WHERE pr.fk_prelevement_lignes =".$rowid;
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->id = $rowid;

View File

@ -40,7 +40,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies', 'bills'));
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'prelevement', '', '', 'bons');
$type = GETPOST('type', 'aZ09');
@ -54,7 +56,9 @@ $format = GETPOST('format', 'aZ09');
$id_bankaccount = GETPOST('id_bankaccount', 'int');
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$hookmanager->initHooks(array('directdebitcreatecard', 'globalcard'));
@ -63,11 +67,15 @@ $hookmanager->initHooks(array('directdebitcreatecard', 'globalcard'));
/*
* Actions
*/
if (GETPOST('cancel', 'alpha')) { $massaction = ''; }
if (GETPOST('cancel', 'alpha')) {
$massaction = '';
}
$parameters = array('mode' => $mode, 'format' => $format, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) {
// Change customer bank information to withdraw
@ -79,14 +87,14 @@ if (empty($reshook)) {
if ($action == 'create') {
$default_account=($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT');
if ($id_bankaccount != $conf->global->{$default_account}){
if ($id_bankaccount != $conf->global->{$default_account}) {
$res = dolibarr_set_const($db, $default_account, $id_bankaccount, 'chaine', 0, '', $conf->entity); //Set as default
}
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$bank = new Account($db);
$bank->fetch($conf->global->{$default_account});
if (empty($bank->ics) || empty($bank->ics_transfer)){
if (empty($bank->ics) || empty($bank->ics_transfer)) {
$errormessage = str_replace('{url}', $bank->getNomUrl(1), $langs->trans("ErrorICSmissing", '{url}'));
setEventMessages($errormessage, null, 'errors');
header("Location: ".DOL_URL_ROOT.'/compta/prelevement/create.php');
@ -148,7 +156,9 @@ $arrayofselected = is_array($toselect) ? $toselect : array();
// List of mass actions available
$arrayofmassactions = array(
);
if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
llxHeader('', $langs->trans("NewStandingOrder"));
@ -180,8 +190,7 @@ print dol_get_fiche_head();
$nb = $bprev->nbOfInvoiceToPay($type);
$pricetowithdraw = $bprev->SommeAPrelever($type);
if ($nb < 0)
{
if ($nb < 0) {
dol_print_error($bprev->error);
}
print '<table class="border centpercent tableforfield">';
@ -205,7 +214,9 @@ print '</tr>';
print '</table>';
print '</div>';
if ($mesg) print $mesg;
if ($mesg) {
print $mesg;
}
print '<div class="tabsAction">'."\n";
@ -213,14 +224,14 @@ print '<form action="'.$_SERVER['PHP_SELF'].'?action=create" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="type" value="'.$type.'">';
if ($nb) {
if ($pricetowithdraw) {
print $langs->trans('BankToReceiveWithdraw').': ';
$form->select_comptes($conf->global->PRELEVEMENT_ID_BANKACCOUNT, 'id_bankaccount', 0, "courant=1");
print ' - ';
if ($pricetowithdraw) {
print $langs->trans('BankToReceiveWithdraw').': ';
$form->select_comptes($conf->global->PRELEVEMENT_ID_BANKACCOUNT, 'id_bankaccount', 0, "courant=1");
print ' - ';
print $langs->trans('ExecutionDate').' ';
$datere = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
print $form->selectDate($datere, 're');
print $langs->trans('ExecutionDate').' ';
$datere = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
print $form->selectDate($datere, 're');
if ($mysoc->isInEEC()) {
@ -307,7 +318,9 @@ if ($type == 'bank-transfer') {
} else {
$sql .= " AND pfd.fk_facture = f.rowid";
}
if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid;
if ($socid > 0) {
$sql .= " AND f.fk_soc = ".$socid;
}
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
@ -323,15 +336,20 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$param = '';
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if ($socid) $param .= '&socid='.urlencode($socid);
if ($option) $param .= "&option=".urlencode($option);
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($socid) {
$param .= '&socid='.urlencode($socid);
}
if ($option) {
$param .= "&option=".urlencode($option);
}
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
@ -359,19 +377,16 @@ if ($resql)
print '<td>'.$langs->trans("RUM").'</td>';
print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
print '<td class="right">'.$langs->trans("DateRequest").'</td>';
if ($massactionbutton || $massaction ) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
print '<td align="center">'.$form->showCheckAddButtons('checkforselect', 1).'</td>';
}
print '</tr>';
if ($num)
{
if ($num) {
require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
$bac = new CompanyBankAccount($db);
while ($i < $num && $i < $limit)
{
while ($i < $num && $i < $limit) {
$obj = $db->fetch_object($resql);
$bac->fetch(0, $obj->socid);
@ -394,7 +409,9 @@ if ($resql)
// RIB
print '<td>';
print $bac->iban.(($bac->iban && $bac->bic) ? ' / ' : '').$bac->bic;
if ($bac->verif() <= 0) print img_warning('Error on default bank number for IBAN : '.$bac->error_message);
if ($bac->verif() <= 0) {
print img_warning('Error on default bank number for IBAN : '.$bac->error_message);
}
print '</td>';
// RUM
@ -404,7 +421,9 @@ if ($resql)
print $rumtoshow;
$format = $thirdpartystatic->display_rib('format');
if ($type != 'bank-transfer') {
if ($format) print ' ('.$format.')';
if ($format) {
print ' ('.$format.')';
}
}
} else {
print img_warning($langs->trans("NoBankAccountDefined"));
@ -419,11 +438,12 @@ if ($resql)
print dol_print_date($db->jdate($obj->date_demande), 'day');
print '</td>';
// Action column
if ($massactionbutton || $massaction ) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
print '<td class="nowrap center">';
$selected = 0;
if (in_array($obj->request_row_id, $arrayofselected)) $selected = 1;
if (in_array($obj->request_row_id, $arrayofselected)) {
$selected = 1;
}
print '<input id="cb'.$obj->request_row_id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->request_row_id.'"'.($selected ? ' checked="checked"' : '').'>';
print '</td>';
}
@ -459,41 +479,41 @@ $sql.=$db->plimit($limit);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
$num = $db->num_rows($result);
$i = 0;
print"\n<!-- debut table -->\n";
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td>';
print '<td class="center">'.$langs->trans("Date").'</td><td class="right">'.$langs->trans("Amount").'</td>';
print '</tr>';
print"\n<!-- debut table -->\n";
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td>';
print '<td class="center">'.$langs->trans("Date").'</td><td class="right">'.$langs->trans("Amount").'</td>';
print '</tr>';
while ($i < min($num,$limit))
{
$obj = $db->fetch_object($result);
while ($i < min($num,$limit))
{
$obj = $db->fetch_object($result);
print '<tr class="oddeven">';
print '<tr class="oddeven">';
print "<td>";
$bprev->id=$obj->rowid;
$bprev->ref=$obj->ref;
print $bprev->getNomUrl(1);
print "</td>\n";
print "<td>";
$bprev->id=$obj->rowid;
$bprev->ref=$obj->ref;
print $bprev->getNomUrl(1);
print "</td>\n";
print '<td class="center">'.dol_print_date($db->jdate($obj->datec),'day')."</td>\n";
print '<td class="center">'.dol_print_date($db->jdate($obj->datec),'day')."</td>\n";
print '<td class="right">'.price($obj->amount,0,$langs,0,0,-1,$conf->currency)."</td>\n";
print '<td class="right">'.price($obj->amount,0,$langs,0,0,-1,$conf->currency)."</td>\n";
print "</tr>\n";
$i++;
}
print "</table><br>";
$db->free($result);
print "</tr>\n";
$i++;
}
print "</table><br>";
$db->free($result);
}
else
{
dol_print_error($db);
dol_print_error($db);
}
*/

View File

@ -37,7 +37,9 @@ $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
// Security check
$socid = GETPOST('socid', 'int');
$status = GETPOST('status', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'prelevement', '', '', 'bons');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
@ -54,12 +56,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
$page = 0;
} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "f.ref";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "f.ref";
}
$massactionbutton = '';
@ -72,11 +80,12 @@ $hookmanager->initHooks(array('withdrawalstodolist'));
$parameters = array('socid' => $socid, 'limit' => $limit, 'page' => $page, 'offset' => $offset);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
// Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
$search_facture = '';
$search_societe = '';
$search_array_options = array();
@ -123,17 +132,26 @@ if ($type != 'bank-transfer') {
}
$sql .= " ".MAIN_DB_PREFIX."societe as s,";
$sql .= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE s.rowid = f.fk_soc";
$sql .= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$status) $sql .= " AND pfd.traite = 0";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
if (!$status) {
$sql .= " AND pfd.traite = 0";
}
$sql .= " AND pfd.ext_payment_id IS NULL";
if ($status) $sql .= " AND pfd.traite = ".$status;
if ($status) {
$sql .= " AND pfd.traite = ".$status;
}
$sql .= " AND f.total_ttc > 0";
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS))
{
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
$sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
}
if ($type != 'bank-transfer') {
@ -141,32 +159,32 @@ if ($type != 'bank-transfer') {
} else {
$sql .= " AND pfd.fk_facture_fourn = f.rowid";
}
if ($search_facture) $sql .= natural_search("f.ref", $search_facture);
if ($search_societe) $sql .= natural_search("s.nom", $search_societe);
if ($search_facture) {
$sql .= natural_search("f.ref", $search_facture);
}
if ($search_societe) {
$sql .= natural_search("s.nom", $search_societe);
}
$sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$resql = $db->query($sql);
$nbtotalofrecords = $db->num_rows($resql);
if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
$page = 0;
$offset = 0;
}
}
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
{
if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
$num = $nbtotalofrecords;
} else {
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($db);
exit;
}
@ -182,7 +200,9 @@ if ($type == 'bank-transfer') {
}
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" id="searchFormList" name="searchFormList">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
@ -226,10 +246,11 @@ print '</td>';
print '</tr>';
$i = 0;
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($resql);
if (empty($obj)) break; // Should not happen
if (empty($obj)) {
break; // Should not happen
}
$invoicestatic->fetch($obj->rowid);

View File

@ -35,7 +35,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->loadLangs(array('banks', 'categories', 'bills', 'companies', 'withdrawals'));
// Securite acces client
if ($user->socid > 0) accessforbidden();
if ($user->socid > 0) {
accessforbidden();
}
// Get supervariables
$id = GETPOST('id', 'int');
@ -48,12 +50,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortfield) $sortfield = 'p.ref';
if (!$sortorder) $sortorder = 'DESC';
if (!$sortfield) {
$sortfield = 'p.ref';
}
if (!$sortorder) {
$sortorder = 'DESC';
}
$object = new BonPrelevement($db);
@ -79,10 +87,8 @@ $thirdpartytmp = new Societe($db);
llxHeader('', $langs->trans("WithdrawalsReceipts"));
if ($id > 0 || $ref)
{
if ($object->fetch($id, $ref) >= 0)
{
if ($id > 0 || $ref) {
if ($object->fetch($id, $ref) >= 0) {
$head = prelevement_prepare_head($object);
print dol_get_fiche_head($head, 'invoices', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
@ -98,8 +104,7 @@ if ($id > 0 || $ref)
print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
if ($object->date_trans <> 0)
{
if ($object->date_trans <> 0) {
$muser = new User($db);
$muser->fetch($object->user_trans);
@ -110,8 +115,7 @@ if ($id > 0 || $ref)
print $object->methodes_trans[$object->method_trans];
print '</td></tr>';
}
if ($object->date_credit <> 0)
{
if ($object->date_credit <> 0) {
print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
print dol_print_date($object->date_credit, 'day');
print '</td></tr>';
@ -129,22 +133,29 @@ if ($id > 0 || $ref)
print '<tr><td class="titlefield">';
$labelofbankfield = "BankToReceiveWithdraw";
if ($object->type == 'bank-transfer') $labelofbankfield = 'BankToPayCreditTransfer';
if ($object->type == 'bank-transfer') {
$labelofbankfield = 'BankToPayCreditTransfer';
}
print $langs->trans($labelofbankfield);
print '</td>';
print '<td>';
if ($acc->id > 0)
if ($acc->id > 0) {
print $acc->getNomUrl(1);
}
print '</td>';
print '</tr>';
print '<tr><td class="titlefield">';
$labelfororderfield = 'WithdrawalFile';
if ($object->type == 'bank-transfer') $labelfororderfield = 'CreditTransferFile';
if ($object->type == 'bank-transfer') {
$labelfororderfield = 'CreditTransferFile';
}
print $langs->trans($labelfororderfield).'</td><td>';
$relativepath = 'receipts/'.$object->ref.'.xml';
$modulepart = 'prelevement';
if ($object->type == 'bank-transfer') $modulepart = 'paymentbybanktransfer';
if ($object->type == 'bank-transfer') {
$modulepart = 'paymentbybanktransfer';
}
print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath.'</a>';
print '</td></tr></table>';
@ -152,7 +163,7 @@ if ($id > 0 || $ref)
print dol_get_fiche_end();
} else {
dol_print_error($db);
dol_print_error($db);
}
}
@ -183,18 +194,20 @@ if ($object->type != 'bank-transfer') {
} else {
$sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
}
if ($object->id > 0) $sql .= " AND p.rowid=".$object->id;
if ($socid) $sql .= " AND s.rowid = ".$socid;
if ($object->id > 0) {
$sql .= " AND p.rowid=".$object->id;
}
if ($socid) {
$sql .= " AND s.rowid = ".$socid;
}
$sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$resql = $db->query($sql);
$nbtotalofrecords = $db->num_rows($resql);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@ -203,16 +216,17 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
$param = "&id=".$id;
$param = "&id=".$id;
// Lines of title fields
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
@ -226,58 +240,57 @@ if ($resql)
print_barre_liste($langs->trans("Invoices"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit);
print"\n<!-- debut table -->\n";
print"\n<!-- debut table -->\n";
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="liste centpercent">';
print '<tr class="liste_titre">';
print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
print_liste_field_titre("AmountInvoice", $_SERVER["PHP_SELF"], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder);
print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "pl.amount", "", $param, 'class="right"', $sortfield, $sortorder);
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, 'align="center"', $sortfield, $sortorder);
print '<table class="liste centpercent">';
print '<tr class="liste_titre">';
print_liste_field_titre("Bill", $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $param, '', $sortfield, $sortorder);
print_liste_field_titre("AmountInvoice", $_SERVER["PHP_SELF"], "f.total_ttc", "", $param, 'class="right"', $sortfield, $sortorder);
print_liste_field_titre("AmountRequested", $_SERVER["PHP_SELF"], "pl.amount", "", $param, 'class="right"', $sortfield, $sortorder);
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", $param, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre('');
print "</tr>\n";
$totalinvoices = 0;
$totalinvoices = 0;
$totalamount_requested = 0;
$invoicetmpcustomer = new Facture($db);
$invoicetmpsupplier = new FactureFournisseur($db);
while ($i < min($num, $limit))
{
$obj = $db->fetch_object($resql);
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($resql);
if ($obj->type == 'bank-transfer') {
$invoicetmp = $invoicetmpsupplier;
} else {
$invoicetmp = $invoicetmpcustomer;
}
$invoicetmp->fetch($obj->facid);
if ($obj->type == 'bank-transfer') {
$invoicetmp = $invoicetmpsupplier;
} else {
$invoicetmp = $invoicetmpcustomer;
}
$invoicetmp->fetch($obj->facid);
$thirdpartytmp->fetch($obj->socid);
$thirdpartytmp->fetch($obj->socid);
print '<tr class="oddeven">';
print '<tr class="oddeven">';
print "<td>";
print $invoicetmp->getNomUrl(1);
print "<td>";
print $invoicetmp->getNomUrl(1);
print "</td>\n";
print '<td>';
print $thirdpartytmp->getNomUrl(1);
print "</td>\n";
print '<td>';
print $thirdpartytmp->getNomUrl(1);
print "</td>\n";
// Amount of invoice
print '<td class="right">'.price($obj->total_ttc)."</td>\n";
// Amount of invoice
print '<td class="right">'.price($obj->total_ttc)."</td>\n";
// Amount requested
print '<td class="right">'.price($obj->amount_requested)."</td>\n";
// Amount requested
print '<td class="right">'.price($obj->amount_requested)."</td>\n";
// Status of requests
print '<td class="center">';
// Status of requests
print '<td class="center">';
if ($obj->statut == 0) {
print '-';
if ($obj->statut == 0) {
print '-';
} elseif ($obj->statut == 2) {
if ($obj->type == 'bank-transfer') {
print $langs->trans("StatusDebited");
@ -285,42 +298,43 @@ if ($resql)
print $langs->trans("StatusCredited");
}
} elseif ($obj->statut == 3) {
print '<b>'.$langs->trans("StatusRefused").'</b>';
print '<b>'.$langs->trans("StatusRefused").'</b>';
}
print "</td>";
print "</td>";
print "<td></td>";
print "<td></td>";
print "</tr>\n";
print "</tr>\n";
$totalinvoices += $obj->total_ttc;
$totalamount_requested += $obj->amount_requested;
$totalinvoices += $obj->total_ttc;
$totalamount_requested += $obj->amount_requested;
$i++;
$i++;
}
if ($num > 0)
{
print '<tr class="liste_total">';
print '<td>'.$langs->trans("Total").'</td>';
print '<td>&nbsp;</td>';
print '<td class="right">';
if ($num > 0) {
print '<tr class="liste_total">';
print '<td>'.$langs->trans("Total").'</td>';
print '<td>&nbsp;</td>';
print '<td class="right">';
//if ($totalinvoices != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices"); // It is normal to have total that differs. For an amount of invoice of 100, request to pay may be 50 only.
if ($totalamount_requested != $object->amount) print img_warning("AmountOfFileDiffersFromSumOfInvoices");
if ($totalamount_requested != $object->amount) {
print img_warning("AmountOfFileDiffersFromSumOfInvoices");
}
print "</td>\n";
print '<td class="right">';
print '<td class="right">';
print price($totalamount_requested);
print "</td>\n";
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print "</tr>\n";
print "</td>\n";
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print "</tr>\n";
}
print "</table>";
print '</div>';
print "</table>";
print '</div>';
$db->free($result);
$db->free($result);
} else {
dol_print_error($db);
}

View File

@ -35,7 +35,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->loadLangs(array("banks", "categories", 'withdrawals', 'bills'));
// Security check
if ($user->socid > 0) accessforbidden();
if ($user->socid > 0) {
accessforbidden();
}
// Get supervariables
$prev_id = GETPOST('id', 'int');
@ -48,7 +50,9 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
@ -73,10 +77,8 @@ if (!$user->rights->paymentbybanktransfer->read && $object->type == 'bank-transf
llxHeader('', $langs->trans("WithdrawalsReceipts"));
if ($prev_id > 0 || $ref)
{
if ($object->fetch($prev_id, $ref) >= 0)
{
if ($prev_id > 0 || $ref) {
if ($object->fetch($prev_id, $ref) >= 0) {
$head = prelevement_prepare_head($object);
print dol_get_fiche_head($head, 'rejects', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
@ -92,8 +94,7 @@ if ($prev_id > 0 || $ref)
print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
if ($object->date_trans <> 0)
{
if ($object->date_trans <> 0) {
$muser = new User($db);
$muser->fetch($object->user_trans);
@ -104,8 +105,7 @@ if ($prev_id > 0 || $ref)
print $object->methodes_trans[$object->method_trans];
print '</td></tr>';
}
if ($object->date_credit <> 0)
{
if ($object->date_credit <> 0) {
print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
print dol_print_date($object->date_credit, 'day');
print '</td></tr>';
@ -123,22 +123,29 @@ if ($prev_id > 0 || $ref)
print '<tr><td class="titlefield">';
$labelofbankfield = "BankToReceiveWithdraw";
if ($object->type == 'bank-transfer') $labelofbankfield = 'BankToPayCreditTransfer';
if ($object->type == 'bank-transfer') {
$labelofbankfield = 'BankToPayCreditTransfer';
}
print $langs->trans($labelofbankfield);
print '</td>';
print '<td>';
if ($acc->id > 0)
if ($acc->id > 0) {
print $acc->getNomUrl(1);
}
print '</td>';
print '</tr>';
print '<tr><td class="titlefield">';
$labelfororderfield = 'WithdrawalFile';
if ($object->type == 'bank-transfer') $labelfororderfield = 'CreditTransferFile';
if ($object->type == 'bank-transfer') {
$labelfororderfield = 'CreditTransferFile';
}
print $langs->trans($labelfororderfield).'</td><td>';
$relativepath = 'receipts/'.$object->ref.'.xml';
$modulepart = 'prelevement';
if ($object->type == 'bank-transfer') $modulepart = 'paymentbybanktransfer';
if ($object->type == 'bank-transfer') {
$modulepart = 'paymentbybanktransfer';
}
print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath.'</a>';
print '</td></tr></table>';
@ -146,7 +153,7 @@ if ($prev_id > 0 || $ref)
print dol_get_fiche_end();
} else {
dol_print_error($db);
dol_print_error($db);
}
}
@ -169,17 +176,17 @@ $sql .= " AND p.entity = ".$conf->entity;
$sql .= " AND pl.fk_soc = s.rowid";
$sql .= " AND pl.statut = 3 ";
$sql .= " AND pr.fk_prelevement_lignes = pl.rowid";
if ($socid) $sql .= " AND s.rowid = ".$socid;
if ($socid) {
$sql .= " AND s.rowid = ".$socid;
}
$sql .= " ORDER BY pl.amount DESC";
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@ -188,26 +195,23 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
if ($resql) {
$num = $db->num_rows($resql);
print_barre_liste($langs->trans("Rejects"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
print_barre_liste($langs->trans("Rejects"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
print"\n<!-- debut table -->\n";
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Line").'</td><td>'.$langs->trans("ThirdParty").'</td><td class="right">'.$langs->trans("Amount").'</td>';
print '<td>'.$langs->trans("Reason").'</td><td align="center">'.$langs->trans("ToBill").'</td><td class="center">'.$langs->trans("Invoice").'</td></tr>';
print"\n<!-- debut table -->\n";
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Line").'</td><td>'.$langs->trans("ThirdParty").'</td><td class="right">'.$langs->trans("Amount").'</td>';
print '<td>'.$langs->trans("Reason").'</td><td align="center">'.$langs->trans("ToBill").'</td><td class="center">'.$langs->trans("Invoice").'</td></tr>';
$total = 0;
if ($num > 0)
{
$i = 0;
while ($i < $num)
{
if ($num > 0) {
$i = 0;
while ($i < $num) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven"><td>';
@ -233,8 +237,7 @@ if ($resql)
print '<tr><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
}
if ($num > 0)
{
if ($num > 0) {
print '<tr class="liste_total"><td>&nbsp;</td>';
print '<td class="liste_total">'.$langs->trans("Total").'</td>';
print '<td class="right">'.price($total)."</td>\n";

View File

@ -33,7 +33,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->loadLangs(array("banks", "categories", 'withdrawals', 'bills'));
// Security check
if ($user->socid > 0) accessforbidden();
if ($user->socid > 0) {
accessforbidden();
}
// Get supervariables
$prev_id = GETPOST('id', 'int');
@ -46,7 +48,9 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
@ -72,10 +76,8 @@ if (!$user->rights->paymentbybanktransfer->read && $object->type == 'bank-transf
llxHeader('', $langs->trans("WithdrawalsReceipts"));
if ($prev_id > 0 || $ref)
{
if ($object->fetch($prev_id, $ref) >= 0)
{
if ($prev_id > 0 || $ref) {
if ($object->fetch($prev_id, $ref) >= 0) {
$head = prelevement_prepare_head($object);
print dol_get_fiche_head($head, 'statistics', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
@ -91,8 +93,7 @@ if ($prev_id > 0 || $ref)
print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
if ($object->date_trans <> 0)
{
if ($object->date_trans <> 0) {
$muser = new User($db);
$muser->fetch($object->user_trans);
@ -103,8 +104,7 @@ if ($prev_id > 0 || $ref)
print $object->methodes_trans[$object->method_trans];
print '</td></tr>';
}
if ($object->date_credit <> 0)
{
if ($object->date_credit <> 0) {
print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
print dol_print_date($object->date_credit, 'day');
print '</td></tr>';
@ -122,22 +122,29 @@ if ($prev_id > 0 || $ref)
print '<tr><td class="titlefield">';
$labelofbankfield = "BankToReceiveWithdraw";
if ($object->type == 'bank-transfer') $labelofbankfield = 'BankToPayCreditTransfer';
if ($object->type == 'bank-transfer') {
$labelofbankfield = 'BankToPayCreditTransfer';
}
print $langs->trans($labelofbankfield);
print '</td>';
print '<td>';
if ($acc->id > 0)
if ($acc->id > 0) {
print $acc->getNomUrl(1);
}
print '</td>';
print '</tr>';
print '<tr><td class="titlefield">';
$labelfororderfield = 'WithdrawalFile';
if ($object->type == 'bank-transfer') $labelfororderfield = 'CreditTransferFile';
if ($object->type == 'bank-transfer') {
$labelfororderfield = 'CreditTransferFile';
}
print $langs->trans($labelfororderfield).'</td><td>';
$relativepath = 'receipts/'.$object->ref.'.xml';
$modulepart = 'prelevement';
if ($object->type == 'bank-transfer') $modulepart = 'paymentbybanktransfer';
if ($object->type == 'bank-transfer') {
$modulepart = 'paymentbybanktransfer';
}
print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath).'">'.$relativepath.'</a>';
print '</td></tr></table>';
@ -159,8 +166,7 @@ if ($prev_id > 0 || $ref)
$sql .= " GROUP BY pl.statut";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -171,8 +177,7 @@ if ($prev_id > 0 || $ref)
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Status").'</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
print '<tr class="oddeven"><td>';
@ -183,7 +188,9 @@ if ($prev_id > 0 || $ref)
print price($row[0]);
print '</td><td class="right">';
if ($object->amount) print round($row[0] / $object->amount * 100, 2)." %";
if ($object->amount) {
print round($row[0] / $object->amount * 100, 2)." %";
}
print '</td>';
print "</tr>\n";

View File

@ -38,7 +38,9 @@ $langs->loadLangs(array('banks', 'categories', 'withdrawals'));
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'prelevement', '', '');
@ -55,8 +57,7 @@ $result = restrictedArea($user, 'prelevement', '', '');
llxHeader('', $langs->trans("CustomersStandingOrdersArea"));
if (prelevement_check_config() < 0)
{
if (prelevement_check_config() < 0) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Withdraw")), null, 'errors');
}
@ -97,24 +98,28 @@ $sql .= " pfd.date_demande, pfd.amount,";
$sql .= " s.nom as name, s.email, s.rowid as socid";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
$sql .= " ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
$sql .= " WHERE s.rowid = f.fk_soc";
$sql .= " AND f.entity IN (".getEntity('invoice').")";
$sql .= " AND f.total_ttc > 0";
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS))
{
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
$sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
}
$sql .= " AND pfd.traite = 0";
$sql .= " AND pfd.ext_payment_id IS NULL";
$sql .= " AND pfd.fk_facture = f.rowid";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) {
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND f.fk_soc = ".$socid;
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -122,10 +127,8 @@ if ($resql)
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th colspan="5">'.$langs->trans("InvoiceWaitingWithdraw").' ('.$num.')</th></tr>';
if ($num)
{
while ($i < $num && $i < 20)
{
if ($num) {
while ($i < $num && $i < 20) {
$obj = $db->fetch_object($resql);
$invoicestatic->id = $obj->rowid;
@ -186,8 +189,7 @@ $sql .= " ORDER BY datec DESC";
$sql .= $db->plimit($limit);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
@ -202,8 +204,7 @@ if ($result)
print '</tr>';
if ($num > 0) {
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($result);

View File

@ -36,7 +36,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->loadlangs(array('banks', 'categories', 'bills', 'withdrawals'));
// Security check
if ($user->socid > 0) accessforbidden();
if ($user->socid > 0) {
accessforbidden();
}
// Get supervariables
$action = GETPOST('action', 'aZ09');
@ -49,52 +51,49 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortorder = GETPOST('sortorder', 'aZ09comma');
$sortfield = GETPOST('sortfield', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if ($page == -1 || $page == null) { $page = 0; }
if ($page == -1 || $page == null) {
$page = 0;
}
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if ($sortorder == "") $sortorder = "DESC";
if ($sortfield == "") $sortfield = "pl.fk_soc";
if ($sortorder == "") {
$sortorder = "DESC";
}
if ($sortfield == "") {
$sortfield = "pl.fk_soc";
}
/*
* Actions
*/
if ($action == 'confirm_rejet')
{
if (GETPOST("confirm") == 'yes')
{
if (GETPOST('remonth', 'int'))
{
if ($action == 'confirm_rejet') {
if (GETPOST("confirm") == 'yes') {
if (GETPOST('remonth', 'int')) {
$daterej = mktime(2, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
}
if (empty($daterej))
{
if (empty($daterej)) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
} elseif ($daterej > dol_now())
{
} elseif ($daterej > dol_now()) {
$error++;
$langs->load("error");
setEventMessages($langs->transnoentities("ErrorDateMustBeBeforeToday"), null, 'errors');
}
if (GETPOST('motif', 'alpha') == 0)
{
if (GETPOST('motif', 'alpha') == 0) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefusedReason")), null, 'errors');
}
if (!$error)
{
if (!$error) {
$lipre = new LignePrelevement($db);
if ($lipre->fetch($id) == 0)
{
if ($lipre->fetch($id) == 0) {
$rej = new RejetPrelevement($db, $user, $type);
$rej->create($user, $id, GETPOST('motif', 'alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer', 'int'));
@ -133,12 +132,10 @@ $head[$h][1] = $title;
$hselected = $h;
$h++;
if ($id)
{
if ($id) {
$lipre = new LignePrelevement($db);
if ($lipre->fetch($id) >= 0)
{
if ($lipre->fetch($id) >= 0) {
$bon = new BonPrelevement($db);
$bon->fetch($lipre->bon_rowid);
@ -156,16 +153,13 @@ if ($id)
print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($lipre->amount).'</td></tr>';
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$lipre->LibStatut($lipre->statut, 1).'</td></tr>';
if ($lipre->statut == 3)
{
if ($lipre->statut == 3) {
$rej = new RejetPrelevement($db, $user, $type);
$resf = $rej->fetch($lipre->id);
if ($resf == 0)
{
if ($resf == 0) {
print '<tr><td>'.$langs->trans("RefusedReason").'</td><td>'.$rej->motif.'</td></tr>';
print '<tr><td>'.$langs->trans("RefusedData").'</td><td>';
if ($rej->date_rejet == 0)
{
if ($rej->date_rejet == 0) {
/* Historique pour certaines install */
print $langs->trans("Unknown");
} else {
@ -184,8 +178,7 @@ if ($id)
dol_print_error($db);
}
if ($action == 'rejet' && $user->rights->prelevement->bons->credit)
{
if ($action == 'rejet' && $user->rights->prelevement->bons->credit) {
$form = new Form($db);
$soc = new Societe($db);
@ -240,13 +233,10 @@ if ($id)
print "<div class=\"tabsAction\">";
if ($action == '')
{
if ($bon->statut == BonPrelevement::STATUS_CREDITED)
{
if ($action == '') {
if ($bon->statut == BonPrelevement::STATUS_CREDITED) {
if ($lipre->statut == 2) {
if ($user->rights->prelevement->bons->credit)
{
if ($user->rights->prelevement->bons->credit) {
print '<a class="butActionDelete" href="line.php?action=rejet&type='.$type.'&id='.$lipre->id.'">'.$langs->trans("StandingOrderReject").'</a>';
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
@ -276,14 +266,15 @@ if ($id)
$sql .= " AND pf.fk_facture = f.rowid";
$sql .= " AND f.entity IN (".getEntity('invoice').")";
$sql .= " AND pl.rowid=".$id;
if ($socid) $sql .= " AND s.rowid = ".$socid;
if ($socid) {
$sql .= " AND s.rowid = ".$socid;
}
$sql .= " ORDER BY $sortfield $sortorder ";
$sql .= $db->plimit($conf->liste_limit + 1, $offset);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
@ -299,8 +290,7 @@ if ($id)
$total = 0;
while ($i < min($num, $conf->liste_limit))
{
while ($i < min($num, $conf->liste_limit)) {
$obj = $db->fetch_object($result);
print '<tr class="oddeven"><td>';

View File

@ -44,7 +44,9 @@ $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'prelevement', '', '', 'bons');
$type = GETPOST('type', 'aZ09');
@ -53,12 +55,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "p.datec";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "p.datec";
}
$search_line = GETPOST('search_line', 'alpha');
$search_bon = GETPOST('search_bon', 'alpha');
@ -77,8 +85,7 @@ $hookmanager->initHooks(array('withdrawalsreceiptslineslist'));
* Actions
*/
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
$search_line = "";
$search_bon = "";
$search_code = "";
@ -117,26 +124,36 @@ if ($type == 'bank-transfer') {
}
$sql .= " AND f.fk_soc = s.rowid";
$sql .= " AND f.entity IN (".getEntity('invoice').")";
if ($socid) $sql .= " AND s.rowid = ".$socid;
if ($search_line) $sql .= " AND pl.rowid = '".$db->escape($search_line)."'";
if ($search_bon) $sql .= natural_search("p.ref", $search_bon);
if ($type == 'bank-transfer') {
if ($search_code) $sql .= natural_search("s.code_fourn", $search_code);
} else {
if ($search_code) $sql .= natural_search("s.code_client", $search_code);
if ($socid) {
$sql .= " AND s.rowid = ".$socid;
}
if ($search_line) {
$sql .= " AND pl.rowid = '".$db->escape($search_line)."'";
}
if ($search_bon) {
$sql .= natural_search("p.ref", $search_bon);
}
if ($type == 'bank-transfer') {
if ($search_code) {
$sql .= natural_search("s.code_fourn", $search_code);
}
} else {
if ($search_code) {
$sql .= natural_search("s.code_client", $search_code);
}
}
if ($search_company) {
$sql .= natural_search("s.nom", $search_company);
}
if ($search_company) $sql .= natural_search("s.nom", $search_company);
$sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@ -145,18 +162,21 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
$param = "&amp;statut=".urlencode($statut);
$param .= "&amp;search_bon=".urlencode($search_bon);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
print"\n<!-- debut table -->\n";
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
@ -206,8 +226,7 @@ if ($result)
print "</tr>\n";
if ($num) {
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($result);
$bon->id = $obj->rowid;

View File

@ -35,7 +35,9 @@ $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'di
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'prelevement', '', '', 'bons');
$type = GETPOST('type', 'aZ09');
@ -44,12 +46,18 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "p.datec";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "p.datec";
}
// Get supervariables
$statut = GETPOST('statut', 'int');
@ -69,8 +77,7 @@ if ($type == 'bank-transfer') {
* Actions
*/
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
{
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
$search_ref = "";
$search_amount = "";
}
@ -90,19 +97,21 @@ if ($type == 'bank-transfer') {
} else {
$sql .= " AND p.type = 'debit-order'";
}
if ($search_ref) $sql .= natural_search("p.ref", $search_ref);
if ($search_amount) $sql .= natural_search("p.amount", $search_amount, 1);
if ($search_ref) {
$sql .= natural_search("p.ref", $search_ref);
}
if ($search_amount) {
$sql .= natural_search("p.amount", $search_amount, 1);
}
$sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
{
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@ -111,27 +120,31 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
$sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
$param .= "&statut=".urlencode($statut);
$selectedfields = '';
$newcardbutton = '';
if ($usercancreate)
{
if ($usercancreate) {
$newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php');
}
// Lines of title fields
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
@ -175,8 +188,7 @@ if ($result)
$directdebitorder = new BonPrelevement($db);
if ($num) {
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($result);
$directdebitorder->id = $obj->rowid;

View File

@ -35,7 +35,9 @@ $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'prelevement', '', '', 'bons');
$type = GETPOST('type', 'aZ09');
@ -45,7 +47,9 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortorder = GETPOST('sortorder', 'aZ09comma');
$sortfield = GETPOST('sortfield', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
@ -62,8 +66,12 @@ if ($type == 'bank-transfer') {
llxHeader('', $title);
if ($sortorder == "") $sortorder = "DESC";
if ($sortfield == "") $sortfield = "p.datec";
if ($sortorder == "") {
$sortorder = "DESC";
}
if ($sortfield == "") {
$sortfield = "p.datec";
}
$rej = new RejetPrelevement($db, $user, $type);
$line = new LignePrelevement($db);
@ -90,13 +98,14 @@ if ($type == 'bank-transfer') {
} else {
$sql .= " AND p.type = 'debit-order'";
}
if ($socid) $sql .= " AND s.rowid = ".$socid;
if ($socid) {
$sql .= " AND s.rowid = ".$socid;
}
$sql .= $db->order($sortfield, $sortorder);
$sql .= $db->plimit($limit + 1, $offset);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
@ -112,8 +121,7 @@ if ($result)
print "</tr>\n";
if ($num) {
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($result);
print '<tr class="oddeven">';

View File

@ -33,7 +33,9 @@ $langs->loadLangs(array('banks', 'categories', 'withdrawals', 'companies'));
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'prelevement', '', '', 'bons');
$type = GETPOST('type', 'aZ09');
@ -64,13 +66,11 @@ if ($type == 'bank-transfer') {
}
$sql .= " AND pb.entity = ".$conf->entity;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
if ($num > 0)
{
if ($num > 0) {
$row = $db->fetch_row($resql);
$total = $row[0];
$nbtotal = $row[1];
@ -100,8 +100,7 @@ if ($type == 'bank-transfer') {
$sql .= " GROUP BY pl.statut";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -111,8 +110,7 @@ if ($resql)
print '<td width="30%">'.$langs->trans("Status").'</td><td align="center">'.$langs->trans("Number").'</td><td class="right">%</td>';
print '<td class="right">'.$langs->trans("Amount").'</td><td class="right">%</td></tr>';
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
print '<tr class="oddeven"><td>';
@ -168,13 +166,11 @@ if ($type == 'bank-transfer') {
$sql .= " AND pb.type = 'debit-order'";
}
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
if ($num > 0)
{
if ($num > 0) {
$row = $db->fetch_row($resql);
$total = $row[0];
$nbtotal = $row[1];
@ -202,8 +198,7 @@ $sql .= " GROUP BY pr.motif";
$sql .= " ORDER BY cc DESC";
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@ -216,8 +211,7 @@ if ($resql)
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
$Rejet = new RejetPrelevement($db, $user, $type);
while ($i < $num)
{
while ($i < $num) {
$row = $db->fetch_row($resql);
print '<tr class="oddeven"><td>';

Some files were not shown because too many files have changed in this diff Show More