--- /tmp/dsg/dolibarr/htdocs/compta/github_accounting-files.php +++ /tmp/dsg/dolibarr/htdocs/compta/client_accounting-files.php @@ -19,10 +19,10 @@ */ /** - * \file htdocs/compta/accounting-files.php - * \ingroup compta - * \brief Page to show portoflio and files of a thirdparty and download it - */ + * \file htdocs/compta/accounting-files.php + * \ingroup compta + * \brief Page to show portoflio and files of a thirdparty and download it + */ 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'); @@ -60,15 +60,15 @@ $date_stopYear = GETPOST('date_stopyear', 'int'); //FIXME doldate $date_stop = ($date_stopDay) ?dol_mktime(23, 59, 59, $date_stopMonth, $date_stopDay, $date_stopYear) : strtotime($date_stop); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('comptafileslist', 'globallist')); // Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$sortfield = GETPOST('sortfield', 'alpha'); +$sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; @@ -79,8 +79,8 @@ $arrayfields = array( - 'type'=>array('label'=>"Type", 'checked'=>1), - 'date'=>array('label'=>"Date", 'checked'=>1), + 'type'=>array('label'=>"Type", 'checked'=>1), + 'date'=>array('label'=>"Date", 'checked'=>1), 'date_due'=>array('label'=>"DateDue", 'checked'=>1), 'ref'=>array('label'=>"Ref", 'checked'=>1), 'documents'=>array('label'=>"Documents", 'checked'=>1), @@ -93,10 +93,10 @@ // Security check if (empty($conf->comptabilite->enabled) && empty($conf->accounting->enabled)) { - accessforbidden(); + accessforbidden(); } if ($user->socid > 0) { - accessforbidden(); + accessforbidden(); } // Define $arrayofentities if multientity is set. @@ -149,244 +149,249 @@ // Customer invoices if (GETPOST('selectinvoices')) { 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; - $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; - $sql .= " AND t.fk_statut <> ".Facture::STATUS_DRAFT; - } - // Vendor invoices + $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.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; + $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; + $sql .= " AND t.fk_statut <> ".Facture::STATUS_DRAFT; + } + // Vendor invoices if (GETPOST('selectsupplierinvoices')) { 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; - $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; - $sql .= " AND t.fk_statut <> ".FactureFournisseur::STATUS_DRAFT; - } - // Expense reports + $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.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; + $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; + $sql .= " AND t.fk_statut <> ".FactureFournisseur::STATUS_DRAFT; + } + // Expense reports if (GETPOST('selectexpensereports')) { 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; - $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; - $sql .= " AND t.fk_statut <> ".ExpenseReport::STATUS_DRAFT; - } - // Donations + $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.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; + $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; + $sql .= " AND t.fk_statut <> ".ExpenseReport::STATUS_DRAFT; + } + // Donations if (GETPOST('selectdonations')) { 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; - $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; - $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT; - } - // Payments of salaries + $sql .= " SELECT t.rowid as id, t.entity, t.ref, paid, amount as total_ht, amount as total_ttc, 0 as total_vat, 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; + $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; + $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT; + } + // Paiements of salaries if (GETPOST('selectpaymentsofsalaries')) { 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; - $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; - //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT; - } - // Social contributions + $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, 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; + $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; + //$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT; + } + // Social contributions if (GETPOST('selectsocialcontributions')) { 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; - $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; - //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT; - } - // Various payments + $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_tva, 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; + $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; + //$sql.=" AND fk_statut <> ".ChargeSociales::STATUS_DRAFT; + } + // Various payments if (GETPOST('selectvariouspayment')) { 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; - $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; - } - // Loan payments + $sql .= " SELECT t.rowid as id, t.entity, t.label as ref, 1 as paid, t.amount as total_ht, t.amount as total_ttc, 0 as total_tva, 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; + $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; + } + // Loan payments if (GETPOST('selectloanspayment')) { 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; - $sql .= " AND l.entity IN (".($entity == 1 ? '0,1' : $entity).')'; + $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_tva, 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; + $sql .= " AND l.entity IN (".($entity == 1 ? '0,1' : $entity).')'; } if ($sql) { - $sql .= $db->order($sortfield, $sortorder); + $sql .= $db->order($sortfield, $sortorder); //print $sql; - $resd = $db->query($sql); - $files = array(); - $link = ''; - - if ($resd) - { - $numd = $db->num_rows($resd); - - $tmpinvoice = new Facture($db); - $tmpinvoicesupplier = new FactureFournisseur($db); - $tmpdonation = new Don($db); - - $upload_dir = ''; - $i = 0; - while ($i < $numd) - { - $objd = $db->fetch_object($resd); - - switch ($objd->item) - { - case "Invoice": - $subdir = ''; - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); - $upload_dir = $conf->facture->dir_output.'/'.$subdir; - $link = "document.php?modulepart=facture&file=".str_replace('/', '%2F', $subdir).'%2F'; - $modulepart = "facture"; - break; - case "SupplierInvoice": - $tmpinvoicesupplier->fetch($objd->id); - $subdir = get_exdir($tmpinvoicesupplier->id, 2, 0, 1, $tmpinvoicesupplier, 'invoice_supplier'); // TODO Use first file - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); - $upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir; - $link = "document.php?modulepart=facture_fournisseur&file=".str_replace('/', '%2F', $subdir).'%2F'; - $modulepart = "facture_fournisseur"; - break; - case "ExpenseReport": - $subdir = ''; - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); - $upload_dir = $conf->expensereport->dir_output.'/'.$subdir; - $link = "document.php?modulepart=expensereport&file=".str_replace('/', '%2F', $subdir).'%2F'; - $modulepart = "expensereport"; - break; - case "SalaryPayment": - $subdir = ''; - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); - $upload_dir = $conf->salaries->dir_output.'/'.$subdir; - $link = "document.php?modulepart=salaries&file=".str_replace('/', '%2F', $subdir).'%2F'; - $modulepart = "salaries"; - break; - case "Donation": - $tmpdonation->fetch($objp->id); - $subdir = get_exdir(0, 0, 0, 0, $tmpdonation, 'donation'); - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); - $upload_dir = $conf->don->dir_output.'/'.$subdir; - $link = "document.php?modulepart=don&file=".str_replace('/', '%2F', $subdir).'%2F'; - $modulepart = "don"; - break; - case "SocialContributions": - $subdir = ''; - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); - $upload_dir = $conf->tax->dir_output.'/'.$subdir; - $link = "document.php?modulepart=tax&file=".str_replace('/', '%2F', $subdir).'%2F'; - $modulepart = "tax"; - break; - case "VariousPayment": - $subdir = ''; - $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); - $upload_dir = $conf->bank->dir_output.'/'.$subdir; - $link = "document.php?modulepart=banque&file=".str_replace('/', '%2F', $subdir).'%2F'; - $modulepart = "banque"; - break; - case "LoanPayment": - // Loan payment has no linked file - $subdir = ''; - $upload_dir = $conf->loan->dir_output.'/'.$subdir; - $link = ""; - $modulepart = ""; - break; - default: - $subdir = ''; - $upload_dir = ''; - $link = ''; - break; - } - - 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) - { - $nofile = array(); - $nofile['id'] = $objd->id; - $nofile['entity'] = $objd->entity; - $nofile['date'] = $db->idate($objd->date); - $nofile['date_due'] = $db->idate($objd->date_due); - $nofile['paid'] = $objd->paid; - $nofile['amount_ht'] = $objd->total_ht; - $nofile['amount_ttc'] = $objd->total_ttc; - $nofile['amount_vat'] = $objd->total_vat; - $nofile['ref'] = ($objd->ref ? $objd->ref : $objd->id); - $nofile['fk'] = $objd->fk_soc; - $nofile['item'] = $objd->item; - $nofile['thirdparty_name'] = $objd->thirdparty_name; - $nofile['thirdparty_code'] = $objd->thirdparty_code; - $nofile['country_code'] = $objd->country_code; - $nofile['vatnum'] = $objd->vatnum; - $nofile['sens'] = $objd->sens; - - $filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile; - } else { - foreach ($files as $key => $file) - { - $file['id'] = $objd->id; - $file['entity'] = $objd->entity; - $file['date'] = $db->idate($objd->date); - $file['date_due'] = $db->idate($objd->date_due); - $file['paid'] = $objd->paid; - $file['amount_ht'] = $objd->total_ht; - $file['amount_ttc'] = $objd->total_ttc; - $file['amount_vat'] = $objd->total_vat; - $file['ref'] = ($objd->ref ? $objd->ref : $objd->id); - $file['fk'] = $objd->fk_soc; - $file['item'] = $objd->item; - $file['thirdparty_name'] = $objd->thirdparty_name; - $file['thirdparty_code'] = $objd->thirdparty_code; - $file['country_code'] = $objd->country_code; - $file['vatnum'] = $objd->vatnum; - $file['sens'] = $objd->sens; - - // Save record into array (only the first time it is found) - if (empty($filesarray[$file['item'].'_'.$file['id']])) { - $filesarray[$file['item'].'_'.$file['id']] = $file; - } - - // Add or concat file - if (empty($filesarray[$file['item'].'_'.$file['id']]['files'])) { - $filesarray[$file['item'].'_'.$file['id']]['files'] = array(); - } - $filesarray[$file['item'].'_'.$file['id']]['files'][] = array( - 'link' => $link.urlencode($file['name']), - 'name'=>$file['name'], - 'ref'=>$file['ref'], - 'fullname' => $file['fullname'], - 'relpath' => '/'.$file['name'], - 'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name'], - 'modulepart' => $modulepart, - 'subdir' => $subdir, - ); - //var_dump($file['item'].'_'.$file['id']); - //var_dump($filesarray[$file['item'].'_'.$file['id']]['files']); - } - } - } - - $i++; - } - } else { - dol_print_error($db); - } - - $db->free($resd); - } else { + $resd = $db->query($sql); + $files = array(); + $link = ''; + + if ($resd) + { + $numd = $db->num_rows($resd); + + $tmpinvoice = new Facture($db); + $tmpinvoicesupplier = new FactureFournisseur($db); + $tmpdonation = new Don($db); + + $upload_dir = ''; + $i = 0; + while ($i < $numd) + { + $objd = $db->fetch_object($resd); + + switch ($objd->item) + { + case "Invoice": + $subdir = ''; + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); + $upload_dir = $conf->facture->dir_output.'/'.$subdir; + $link = "document.php?modulepart=facture&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "facture"; + break; + case "SupplierInvoice": + $tmpinvoicesupplier->fetch($objd->id); + $subdir = get_exdir($tmpinvoicesupplier->id, 2, 0, 1, $tmpinvoicesupplier, 'invoice_supplier'); // TODO Use first file + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); + $upload_dir = $conf->fournisseur->facture->dir_output.'/'.$subdir; + $link = "document.php?modulepart=facture_fournisseur&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "facture_fournisseur"; + break; + case "ExpenseReport": + $subdir = ''; + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->ref); + $upload_dir = $conf->expensereport->dir_output.'/'.$subdir; + $link = "document.php?modulepart=expensereport&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "expensereport"; + break; + case "SalaryPayment": + $subdir = ''; + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); + $upload_dir = $conf->salaries->dir_output.'/'.$subdir; + $link = "document.php?modulepart=salaries&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "salaries"; + break; + case "Donation": + $tmpdonation->fetch($objp->id); + $subdir = get_exdir(0, 0, 0, 0, $tmpdonation, 'donation'); + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); + $upload_dir = $conf->don->dir_output.'/'.$subdir; + $link = "document.php?modulepart=don&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "don"; + break; + case "SocialContributions": + $subdir = ''; + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); + $upload_dir = $conf->tax->dir_output.'/'.$subdir; + $link = "document.php?modulepart=tax&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "tax"; + break; + case "VariousPayment": + $subdir = ''; + $subdir .= ($subdir ? '/' : '').dol_sanitizeFileName($objd->id); + $upload_dir = $conf->bank->dir_output.'/'.$subdir; + $link = "document.php?modulepart=banque&file=".str_replace('/', '%2F', $subdir).'%2F'; + $modulepart = "banque"; + break; + case "LoanPayment": + // Loan payment has no linked file + $subdir = ''; + $upload_dir = $conf->loan->dir_output.'/'.$subdir; + $link = ""; + $modulepart = ""; + break; + default: + $subdir = ''; + $upload_dir = ''; + $link = ''; + break; + } + + 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) + { + $nofile = array(); + $nofile['id'] = $objd->id; + $nofile['entity'] = $objd->entity; + $nofile['date'] = $db->idate($objd->date); + $nofile['date_due'] = $db->idate($objd->date_due); + $nofile['paid'] = $objd->paid; + $nofile['amount_ht'] = $objd->total_ht; + $nofile['amount_ttc'] = $objd->total_ttc; + $nofile['amount_vat'] = $objd->total_vat; + $nofile['ref'] = ($objd->ref ? $objd->ref : $objd->id); + $nofile['fk'] = $objd->fk_soc; + $nofile['item'] = $objd->item; + $nofile['thirdparty_name'] = $objd->thirdparty_name; + $nofile['thirdparty_code'] = $objd->thirdparty_code; + $nofile['country_code'] = $objd->country_code; + $nofile['vatnum'] = $objd->vatnum; + $nofile['sens'] = $objd->sens; + + $filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile; + } + else + { + foreach ($files as $key => $file) + { + $file['id'] = $objd->id; + $file['entity'] = $objd->entity; + $file['date'] = $db->idate($objd->date); + $file['date_due'] = $db->idate($objd->date_due); + $file['paid'] = $objd->paid; + $file['amount_ht'] = $objd->total_ht; + $file['amount_ttc'] = $objd->total_ttc; + $file['amount_vat'] = $objd->total_vat; + $file['ref'] = ($objd->ref ? $objd->ref : $objd->id); + $file['fk'] = $objd->fk_soc; + $file['item'] = $objd->item; + $file['thirdparty_name'] = $objd->thirdparty_name; + $file['thirdparty_code'] = $objd->thirdparty_code; + $file['country_code'] = $objd->country_code; + $file['vatnum'] = $objd->vatnum; + $file['sens'] = $objd->sens; + + // Save record into array (only the first time it is found) + if (empty($filesarray[$file['item'].'_'.$file['id']])) { + $filesarray[$file['item'].'_'.$file['id']] = $file; + } + + // Add or concat file + if (empty($filesarray[$file['item'].'_'.$file['id']]['files'])) { + $filesarray[$file['item'].'_'.$file['id']]['files'] = array(); + } + $filesarray[$file['item'].'_'.$file['id']]['files'][] = array( + 'link' => $link.urlencode($file['name']), + 'name'=>$file['name'], + 'ref'=>$file['ref'], + 'fullname' => $file['fullname'], + 'relpath' => '/'.$file['name'], + 'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name'], + 'modulepart' => $modulepart, + 'subdir' => $subdir, + ); + //var_dump($file['item'].'_'.$file['id']); + //var_dump($filesarray[$file['item'].'_'.$file['id']]['files']); + } + } + } + + $i++; + } + } + else + { + dol_print_error($db); + } + + $db->free($resd); + } + else { setEventMessages($langs->trans("ErrorSelectAtLeastOne"), null, 'errors'); $error++; } @@ -414,81 +419,83 @@ exit; } - dol_mkdir($dirfortmpfile); - - $log = $langs->transnoentitiesnoconv("Type"); - if (!empty($conf->multicompany->enabled) && is_object($mc)) - { - $log .= ','.$langs->transnoentitiesnoconv("Entity"); - } - $log .= ','.$langs->transnoentitiesnoconv("Date"); - $log .= ','.$langs->transnoentitiesnoconv("DateDue"); - $log .= ','.$langs->transnoentitiesnoconv("Ref"); - $log .= ','.$langs->transnoentitiesnoconv("TotalHT"); - $log .= ','.$langs->transnoentitiesnoconv("TotalTTC"); - $log .= ','.$langs->transnoentitiesnoconv("TotalVAT"); - $log .= ','.$langs->transnoentitiesnoconv("Paid"); - $log .= ','.$langs->transnoentitiesnoconv("Document"); - $log .= ','.$langs->transnoentitiesnoconv("ItemID"); - $log .= ','.$langs->transnoentitiesnoconv("ThirdParty"); - $log .= ','.$langs->transnoentitiesnoconv("Code"); - $log .= ','.$langs->transnoentitiesnoconv("Country"); - $log .= ','.$langs->transnoentitiesnoconv("VATIntra"); - $log .= ','.$langs->transnoentitiesnoconv("Sens")."\n"; - $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc')."-".dol_print_date($date_stop, 'dayrfc').'_export.zip'; - - dol_delete_file($zipname); - - $zip = new ZipArchive; - $res = $zip->open($zipname, ZipArchive::OVERWRITE | ZipArchive::CREATE); - if ($res) - { - foreach ($filesarray as $key => $file) - { - if (!empty($file['files'])) { - foreach ($file['files'] as $filecursor) { - if (file_exists($filecursor["fullname"])) { - $zip->addFile($filecursor["fullname"], $filecursor["relpathnamelang"]); - } - } - } - - $log .= '"'.$langs->trans($file['item']).'"'; - 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'); - $log .= ','.dol_print_date($file['date_due'], 'dayrfc'); - $log .= ',"'.$file['ref'].'"'; - $log .= ','.$file['amount_ht']; - $log .= ','.$file['amount_ttc']; - $log .= ','.$file['amount_vat']; - $log .= ','.$file['paid']; - $log .= ',"'.$file["name"].'"'; - $log .= ','.$file['fk']; - $log .= ',"'.$file['thirdparty_name'].'"'; - $log .= ',"'.$file['thirdparty_code'].'"'; - $log .= ',"'.$file['country_code'].'"'; - $log .= ',"'.$file['vatnum'].'"'; - $log .= ',"'.$file['sens'].'"'; - $log .= "\n"; - } - $zip->addFromString('transactions.csv', $log); - $zip->close(); - - ///Then download the zipped file. - header('Content-Type: application/zip'); - header('Content-disposition: attachment; filename='.basename($zipname)); - header('Content-Length: '.filesize($zipname)); - readfile($zipname); - - dol_delete_file($zipname); - - exit(); - } else { - setEventMessages($langs->trans("FailedToOpenFile", $zipname), null, 'errors'); - } + dol_mkdir($dirfortmpfile); + + $log = $langs->transnoentitiesnoconv("Type"); + if (!empty($conf->multicompany->enabled) && is_object($mc)) + { + $log .= ','.$langs->transnoentitiesnoconv("Entity"); + } + $log .= ','.$langs->transnoentitiesnoconv("Date"); + $log .= ','.$langs->transnoentitiesnoconv("DateDue"); + $log .= ','.$langs->transnoentitiesnoconv("Ref"); + $log .= ','.$langs->transnoentitiesnoconv("TotalHT"); + $log .= ','.$langs->transnoentitiesnoconv("TotalTTC"); + $log .= ','.$langs->transnoentitiesnoconv("TotalVAT"); + $log .= ','.$langs->transnoentitiesnoconv("Paid"); + $log .= ','.$langs->transnoentitiesnoconv("Document"); + $log .= ','.$langs->transnoentitiesnoconv("ItemID"); + $log .= ','.$langs->transnoentitiesnoconv("ThirdParty"); + $log .= ','.$langs->transnoentitiesnoconv("Code"); + $log .= ','.$langs->transnoentitiesnoconv("Country"); + $log .= ','.$langs->transnoentitiesnoconv("VATIntra"); + $log .= ','.$langs->transnoentitiesnoconv("Sens")."\n"; + $zipname = $dirfortmpfile.'/'.dol_print_date($date_start, 'dayrfc')."-".dol_print_date($date_stop, 'dayrfc').'_export.zip'; + + dol_delete_file($zipname); + + $zip = new ZipArchive; + $res = $zip->open($zipname, ZipArchive::OVERWRITE | ZipArchive::CREATE); + if ($res) + { + foreach ($filesarray as $key => $file) + { + if (!empty($file['files'])) { + foreach ($file['files'] as $filecursor) { + if (file_exists($filecursor["fullname"])) { + $zip->addFile($filecursor["fullname"], $filecursor["relpathnamelang"]); + } + } + } + + $log .= '"'.$langs->trans($file['item']).'"'; + 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'); + $log .= ','.dol_print_date($file['date_due'], 'dayrfc'); + $log .= ',"'.$file['ref'].'"'; + $log .= ','.$file['amount_ht']; + $log .= ','.$file['amount_ttc']; + $log .= ','.$file['amount_vat']; + $log .= ','.$file['paid']; + $log .= ',"'.$file["name"].'"'; + $log .= ','.$file['fk']; + $log .= ',"'.$file['thirdparty_name'].'"'; + $log .= ',"'.$file['thirdparty_code'].'"'; + $log .= ',"'.$file['country_code'].'"'; + $log .= ',"'.$file['vatnum'].'"'; + $log .= ',"'.$file['sens'].'"'; + $log .= "\n"; + } + $zip->addFromString('transactions.csv', $log); + $zip->close(); + + ///Then download the zipped file. + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename='.basename($zipname)); + header('Content-Length: '.filesize($zipname)); + readfile($zipname); + + dol_delete_file($zipname); + + exit(); + } + else + { + setEventMessages($langs->trans("FailedToOpenFile", $zipname), null, 'errors'); + } } @@ -519,17 +526,14 @@ $head[$h][1] = $langs->trans("AccountantFiles"); $head[$h][2] = 'AccountancyFiles'; -print dol_get_fiche_head($head, 'AccountancyFiles'); +dol_fiche_head($head, 'AccountancyFiles'); print '
'."\n"; print ''; -print ''.$langs->trans("ExportAccountingSourceDocHelp", $langs->transnoentitiesnoconv("Accounting"), $langs->transnoentitiesnoconv("Journals")).'
'; -print '
'; - print $langs->trans("ReportPeriod").': '.$form->selectDate($date_start, 'date_start', 0, 0, 0, "", 1, 1, 0); -print ' - '.$form->selectDate($date_stop, 'date_stop', 0, 0, 0, "", 1, 1, 0)."\n"; +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)) @@ -549,245 +553,220 @@ print '
'; $listofchoices = array( - 'selectinvoices'=>array('label'=>'Invoices', 'lang'=>'bills', 'enabled' => !empty($conf->facture->enabled)), - 'selectsupplierinvoices'=>array('label'=>'BillsSuppliers', 'lang'=>'bills', 'enabled' => !empty($conf->supplier_invoice->enabled)), - 'selectexpensereports'=>array('label'=>'ExpenseReports', 'lang'=>'trips', 'enabled' => !empty($conf->expensereport->enabled)), - 'selectdonations'=>array('label'=>'Donations', 'lang'=>'donation', 'enabled' => !empty($conf->don->enabled)), - 'selectsocialcontributions'=>array('label'=>'SocialContributions', 'enabled' => !empty($conf->tax->enabled)), - 'selectpaymentsofsalaries'=>array('label'=>'SalariesPayments', 'lang'=>'salaries', 'enabled' => !empty($conf->salaries->enabled)), - 'selectvariouspayment'=>array('label'=>'VariousPayment', 'enabled' => !empty($conf->banque->enabled)), - 'selectloanspayment'=>array('label'=>'PaymentLoan', 'enabled' => !empty($conf->loan->enabled)), + 'selectinvoices'=>array('label'=>'Invoices', 'lang'=>'bills'), + 'selectsupplierinvoices'=>array('label'=>'BillsSuppliers', 'lang'=>'bills'), + 'selectexpensereports'=>array('label'=>'ExpenseReports', 'lang'=>'trips'), + 'selectdonations'=>array('label'=>'Donations', 'lang'=>'donation'), + 'selectpaymentsofsalaries'=>array('label'=>'SalariesPayments', 'lang'=>'salaries'), + 'selectsocialcontributions'=>array('label'=>'SocialContributions'), + 'selectvariouspayment'=>array('label'=>'VariousPayment'), + 'selectloanspayment'=>array('label'=>'PaymentLoan'), ); foreach ($listofchoices as $choice => $val) { - if (empty($val['enabled'])) continue; // list not qualified $checked = (((!GETPOSTISSET('search') && $action != 'searchfiles') || GETPOST($choice)) ? ' checked="checked"' : ''); - print '
'; + print '
'.$langs->trans($val['label']).'
'; } print ''; print '
'."\n"; -print dol_get_fiche_end(); +dol_fiche_end(); if (!empty($date_start) && !empty($date_stop)) { - $param = 'action=searchfiles'; - $param .= '&date_startday='.GETPOST('date_startday', 'int'); - $param .= '&date_startmonth='.GETPOST('date_startmonth', 'int'); - $param .= '&date_startyear='.GETPOST('date_startyear', 'int'); - $param .= '&date_stopday='.GETPOST('date_stopday', 'int'); - $param .= '&date_stopmonth='.GETPOST('date_stopmonth', 'int'); - $param .= '&date_stopyear='.GETPOST('date_stopyear', 'int'); - foreach ($listofchoices as $choice => $val) { - $param .= '&'.$choice.'='.(GETPOST($choice, 'int') ? 1 : 0); - } - print '
'."\n"; - print ''; - - echo dol_print_date($date_start, 'day')." - ".dol_print_date($date_stop, 'day'); - - print ''; - print ''; - foreach ($listofchoices as $choice => $val) { - print ''; - } - - print ''; - print '
'."\n"; - - print '
'; - - print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table - print ''; - print ''; - print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "item", "", $param, '', $sortfield, $sortorder, 'nowrap '); - print_liste_field_titre($arrayfields['date']['label'], $_SERVER["PHP_SELF"], "date", "", $param, '', $sortfield, $sortorder, 'center nowrap '); - print_liste_field_titre($arrayfields['date_due']['label'], $_SERVER["PHP_SELF"], "date_due", "", $param, '', $sortfield, $sortorder, 'center nowrap '); - print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'nowraponall '); - print ''; - print ''; - print ''; - print ''; - print ''; + $param = 'action=searchfiles'; + $param .= '&date_startday='.GETPOST('date_startday', 'int'); + $param .= '&date_startmonth='.GETPOST('date_startmonth', 'int'); + $param .= '&date_startyear='.GETPOST('date_startyear', 'int'); + $param .= '&date_stopday='.GETPOST('date_stopday', 'int'); + $param .= '&date_stopmonth='.GETPOST('date_stopmonth', 'int'); + $param .= '&date_stopyear='.GETPOST('date_stopyear', 'int'); + foreach ($listofchoices as $choice => $val) { + $param .= '&'.$choice.'='.(GETPOST($choice, 'int') ? 1 : 0); + } + print ''."\n"; + print ''; + + echo dol_print_date($date_start, 'day')." - ".dol_print_date($date_stop, 'day'); + + print ''; + print ''; + foreach ($listofchoices as $choice => $val) { + print ''; + } + + print ''; + print ''."\n"; + + print '
'; + + print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table + print '
'.$langs->trans("Document").''.$langs->trans("Paid").''.$langs->trans("TotalHT").($conf->multicurrency->enabled ? ' ('.$conf->currency.')' : '').''.$langs->trans("TotalTTC").($conf->multicurrency->enabled ? ' ('.$conf->currency.')' : '').''.$langs->trans("TotalVAT").($conf->multicurrency->enabled ? ' ('.$conf->currency.')' : '').'
'; + print ''; + print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "item", "", $param, '', $sortfield, $sortorder, 'nowrap '); + print_liste_field_titre($arrayfields['date']['label'], $_SERVER["PHP_SELF"], "date", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + print_liste_field_titre($arrayfields['date_due']['label'], $_SERVER["PHP_SELF"], "date_due", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'nowraponall '); + print ''; + print ''; + print ''; + print ''; + print ''; print ''; print ''; print ''; - print ''; - if (!empty($conf->multicurrency->enabled)) print ''; - print ''; - if ($result) - { - $TData = dol_sort_array($filesarray, $sortfield, $sortorder); - - if (empty($TData)) - { - print ''; - if (!empty($conf->multicurrency->enabled)) { - print ''; - } - print ''; - } else { - // Sort array by date ASC to calculate balance - - $totalET_debit = 0; - $totalIT_debit = 0; - $totalVAT_debit = 0; - $totalET_credit = 0; - $totalIT_credit = 0; - $totalVAT_credit = 0; - - // Display array - 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']; - print ''; - - // Type - print ''; - - // Date - print '\n"; - - // Date due - print '\n"; - - // Ref - print ''; + print ''; + if ($result) + { + $TData = dol_sort_array($filesarray, $sortfield, $sortorder); + + if (empty($TData)) + { + print ''; + } + else + { + // Sort array by date ASC to calculate balance + + $totalET_debit = 0; + $totalIT_debit = 0; + $totalVAT_debit = 0; + $totalET_credit = 0; + $totalIT_credit = 0; + $totalVAT_credit = 0; + + // Display array + 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']; + print ''; + + // Type + print ''; + + // Date + print '\n"; + + // Date + print '\n"; + + // Ref + print ''; - - // File link - print '\n"; - - // Paid - print ''; - - // Total ET - print '\n"; - // Total IT - print '\n"; - // Total VAT - print '\n"; - - print '\n"; - - print '\n"; - - print '\n"; - - print '\n"; - - if ($data['sens']) { - $totalET_credit += $data['amount_ht']; - $totalIT_credit += $data['amount_ttc']; - $totalVAT_credit += $data['amount_vat']; - } else { - $totalET_debit -= $data['amount_ht']; - $totalIT_debit -= $data['amount_ttc']; - $totalVAT_debit -= $data['amount_vat']; - } - - if (!empty($conf->multicurrency->enabled)) { - print '\n"; - } - - print "\n"; - } - - // Total credits - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if (!empty($conf->multicurrency->enabled)) { - print ''; - } - print "\n"; - // Total debits - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if (!empty($conf->multicurrency->enabled)) { - print ''; - } - print "\n"; - // Balance - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if (!empty($conf->multicurrency->enabled)) { - print ''; - } - print "\n"; - } - } - print "
'.$langs->trans("Document").''.$langs->trans("Paid").''.$langs->trans("TotalHT").''.$langs->trans("TotalTTC").''.$langs->trans("TotalVAT").''.$langs->trans("ThirdParty").''.$langs->trans("Code").''.$langs->trans("Country").''.$langs->trans("VATIntra").''.$langs->trans("Currency").'
'.$langs->trans("NoItem").'
'.$langs->trans($data['item']).''; - print dol_print_date($data['date'], 'day'); - print "'; - print dol_print_date($data['date_due'], 'day'); - print "'; + print ''.$langs->trans("VATIntra").'
'.$langs->trans("NoItem").'
'.$langs->trans($data['item']).''; + print dol_print_date($data['date'], 'day'); + print "'; + print dol_print_date($data['date_due'], 'day'); + print "'; if ($data['item'] == 'Invoice') { $invoice->id = $data['id']; - $invoice->ref = $data['ref']; - $invoice->total_ht = $data['amount_ht']; - $invoice->total_ttc = $data['amount_ttc']; - $invoice->total_tva = $data['amount_vat']; - $invoice->multicurrency_code = $data['currency']; - print $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0); + $invoice->ref = $data['ref']; + print $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0); } elseif ($data['item'] == 'SupplierInvoice') { - $supplier_invoice->id = $data['id']; - $supplier_invoice->ref = $data['ref']; - $supplier_invoice->total_ht = $data['amount_ht']; - $supplier_invoice->total_ttc = $data['amount_ttc']; - $supplier_invoice->total_tva = $data['amount_vat']; - $supplier_invoice->multicurrency_code = $data['currency']; - print $supplier_invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0); + $supplier_invoice->id = $data['id']; + $supplier_invoice->ref = $data['ref']; + print $supplier_invoice->getNomUrl(1, '', 0, 0, '', 0, 0, 0); } elseif ($data['item'] == 'ExpenseReport') { - $expensereport->id = $data['id']; - $expensereport->ref = $data['ref']; - print $expensereport->getNomUrl(1, 0, 0, '', 0, 0); + $expensereport->id = $data['id']; + $expensereport->ref = $data['ref']; + print $expensereport->getNomUrl(1, 0, 0, '', 0, 0); } elseif ($data['item'] == 'SalaryPayment') { - $salary_payment->id = $data['id']; - $salary_payment->ref = $data['ref']; - print $salary_payment->getNomUrl(1, '', 0, '', 0); + $salary_payment->id = $data['id']; + $salary_payment->ref = $data['ref']; + print $salary_payment->getNomUrl(1, '', 0, '', 0); } elseif ($data['item'] == 'Donation') { - $don->id = $data['id']; - $don->ref = $data['ref']; - print $don->getNomUrl(1, 0, '', 0); + $don->id = $data['id']; + $don->ref = $data['ref']; + print $don->getNomUrl(1, 0, '', 0); } elseif ($data['item'] == 'SocialContributions') { - $charge_sociales->id = $data['id']; - $charge_sociales->ref = $data['ref']; - print $charge_sociales->getNomUrl(1, 0, 0, 0, 0); + $charge_sociales->id = $data['id']; + $charge_sociales->ref = $data['ref']; + print $charge_sociales->getNomUrl(1, 0, 0, 0, 0); } elseif ($data['item'] == 'VariousPayment') { - $various_payment->id = $data['id']; - $various_payment->ref = $data['ref']; - print $various_payment->getNomUrl(1, '', 0, 0); + $various_payment->id = $data['id']; + $various_payment->ref = $data['ref']; + print $various_payment->getNomUrl(1, '', 0, 0); } elseif ($data['item'] == 'LoanPayment') { - $payment_loan->id = $data['id']; - $payment_loan->ref = $data['ref']; - print $payment_loan->getNomUrl(1, 0, 0, '', 0); + $payment_loan->id = $data['id']; + $payment_loan->ref = $data['ref']; + print $payment_loan->getNomUrl(1, 0, 0, '', 0); } else { - print $data['ref']; + print $data['ref']; } - print ''; - if (!empty($data['files'])) - { - foreach ($data['files'] as $id=>$filecursor) { - print ''.($filecursor['name'] ? $filecursor['name'] : $filecursor['ref']).' '.$formfile->showPreview($filecursor, $filecursor['modulepart'], $filecursor['subdir'].'/'.$filecursor['name']).'
'; - } - } - print "
'.$data['paid'].''.price($data['sens'] ? $data['amount_ht'] : -$data['amount_ht'])."'.price($data['sens'] ? $data['amount_ttc'] : -$data['amount_ttc'])."'.price($data['sens'] ? $data['amount_vat'] : -$data['amount_vat'])."'.$data['thirdparty_name']."'.$data['thirdparty_code']."'.$data['country_code']."'.$data['vatnum']."'.$data['currency']."
'.$langs->trans('Total').' '.$langs->trans('Income').''.price(price2num($totalET_credit, 'MT')).''.price(price2num($totalIT_credit, 'MT')).''.price(price2num($totalVAT_credit, 'MT')).'
'.$langs->trans('Total').' '.$langs->trans('Outcome').''.price(price2num($totalET_debit, 'MT')).''.price(price2num($totalIT_debit, 'MT')).''.price(price2num($totalVAT_debit, 'MT')).'
'.$langs->trans('Total').''.price(price2num($totalET_credit + $totalET_debit, 'MT')).''.price(price2num($totalIT_credit + $totalIT_debit, 'MT')).''.price(price2num($totalVAT_credit + $totalVAT_debit, 'MT')).'
"; - print '
'; + print ''; + + // File link + print ''; + if (!empty($data['files'])) + { + foreach ($data['files'] as $id=>$filecursor) { + print ''.($filecursor['name'] ? $filecursor['name'] : $filecursor['ref']).' '.$formfile->showPreview($filecursor, $filecursor['modulepart'], $filecursor['subdir'].'/'.$filecursor['name']).'
'; + } + } + print "\n"; + + // Paid + print ''.$data['paid'].''; + + // Total ET + print ''.price($data['sens']?$data['amount_ht']:-$data['amount_ht'])."\n"; + // Total IT + print ''.price($data['sens']?$data['amount_ttc']:-$data['amount_ttc'])."\n"; + // Total VAT + print ''.price($data['sens']?$data['amount_vat']:-$data['amount_vat'])."\n"; + + print ''.$data['thirdparty_name']."\n"; + + print ''.$data['thirdparty_code']."\n"; + + print ''.$data['country_code']."\n"; + + print ''.$data['vatnum']."\n"; + + if ($data['sens']) { + $totalET_credit += $data['amount_ht']; + $totalIT_credit += $data['amount_ttc']; + $totalVAT_credit += $data['amount_vat']; + } else { + $totalET_debit -= $data['amount_ht']; + $totalIT_debit -= $data['amount_ttc']; + $totalVAT_debit -= $data['amount_vat']; + } + + print "\n"; + } + + // Total credits + print ''; + print ''.$langs->trans('Total').' '.$langs->trans('Income').''; + print ''.price(price2num($totalET_credit, 'MT')).''; + print ''.price(price2num($totalIT_credit, 'MT')).''; + print ''.price(price2num($totalVAT_credit, 'MT')).''; + print ''; + print "\n"; + // Total debits + print ''; + print ''.$langs->trans('Total').' '.$langs->trans('Outcome').''; + print ''.price(price2num($totalET_debit, 'MT')).''; + print ''.price(price2num($totalIT_debit, 'MT')).''; + print ''.price(price2num($totalVAT_debit, 'MT')).''; + print ''; + print "\n"; + // Balance + print ''; + print ''.$langs->trans('Total').''; + print ''.price(price2num($totalET_credit+$totalET_debit, 'MT')).''; + print ''.price(price2num($totalIT_credit+$totalIT_debit, 'MT')).''; + print ''.price(price2num($totalVAT_credit+$totalVAT_debit, 'MT')).''; + print ''; + print "\n"; + } + } + print ""; + print ''; } --- /tmp/dsg/dolibarr/htdocs/compta/github_ajaxpayment.php +++ /tmp/dsg/dolibarr/htdocs/compta/client_ajaxpayment.php @@ -81,11 +81,13 @@ $remainAmount = $currentRemain - $currentAmount; // To keep value between curRemain and curAmount $result += $remainAmount; // result must be deduced by $currentAmount += $remainAmount; // curAmount put to curRemain - } else { + } else + { $currentAmount = $currentRemain; $result += $currentRemain; } - } else { + } else + { // Reset the substraction for this amount $result += price2num($currentAmount); $currentAmount = 0; --- /tmp/dsg/dolibarr/htdocs/compta/github_clients.php +++ /tmp/dsg/dolibarr/htdocs/compta/client_clients.php @@ -66,7 +66,7 @@ if ($action == 'note') { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='".$db->escape($note)."' WHERE rowid=".$socid; + $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='".$note."' WHERE rowid=".$socid; $result = $db->query($sql); } @@ -196,7 +196,9 @@ print ''; $db->free($resql); -} else { +} +else +{ dol_print_error($db); } --- /tmp/dsg/dolibarr/htdocs/compta/github_index.php +++ /tmp/dsg/dolibarr/htdocs/compta/client_index.php @@ -2,13 +2,11 @@ /* Copyright (C) 2001-2005 Rodolphe Quiedeville * Copyright (C) 2004-2013 Laurent Destailleur * Copyright (C) 2005-2015 Regis Houssin - * Copyright (C) 2015-2020 Juanjo Menent + * Copyright (C) 2015-2016 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2016 Marcos García * Copyright (C) 2019 Nicolas ZABOURI - * Copyright (C) 2020 Tobias Sekan - * Copyright (C) 2020 Josep Lluís Amador * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,9 +32,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; -require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; +if (!empty($conf->commande->enabled)) + require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; +if (!empty($conf->commande->enabled)) + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; +if (!empty($conf->tax->enabled)) + require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; // L'espace compta/treso doit toujours etre actif car c'est un espace partage // par de nombreux modules (banque, facture, commande a facturer, etc...) independamment @@ -50,7 +51,7 @@ if (!empty($conf->commande->enabled)) $langs->load("orders"); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $bid = GETPOST('bid', 'int'); // Security check @@ -61,7 +62,7 @@ $socid = $user->socid; } -$max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT; +$max = 3; // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array $hookmanager->initHooks(array('invoiceindex')); @@ -77,6 +78,9 @@ $now = dol_now(); +$facturestatic = new Facture($db); +$facturesupplierstatic = new FactureFournisseur($db); + $form = new Form($db); $formfile = new FormFile($db); $thirdpartystatic = new Societe($db); @@ -91,43 +95,43 @@ 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) - { - $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) - { - $listofsearchfields['search_supplier_invoice'] = array('text'=>'SupplierInvoice'); - } - if (!empty($conf->don->enabled) && $user->rights->don->lire) - { - $langs->load("donations"); - $listofsearchfields['search_donation'] = array('text'=>'Donation'); - } - - if (count($listofsearchfields)) - { - print '
'; - print ''; + // Search customer invoices + 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) + { + $listofsearchfields['search_supplier_invoice'] = array('text'=>'SupplierInvoice'); + } + if (!empty($conf->don->enabled) && $user->rights->don->lire) + { + $langs->load("donations"); + $listofsearchfields['search_donation'] = array('text'=>'Donation'); + } + + if (count($listofsearchfields)) + { + print ''; + print ''; print '
'; - print ''; - $i = 0; - foreach ($listofsearchfields as $key => $value) - { - if ($i == 0) print ''; - print ''; - print ''; - if ($i == 0) print ''; - print ''; - $i++; - } - print '
'.$langs->trans("Search").'
'; - print '
'; - print '
'; - print '
'; - } + print ''; + $i = 0; + foreach ($listofsearchfields as $key => $value) + { + if ($i == 0) print ''; + print ''; + print ''; + if ($i == 0) print ''; + print ''; + $i++; + } + print '
'.$langs->trans("Search").'
'; + print ''; + print ''; + print '
'; + } } @@ -136,18 +140,15 @@ */ 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"; - $sql .= ", f.type, f.fk_statut as status, f.paye"; - $sql .= ", s.nom as name"; - $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"; + $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"; + $sql .= ", f.type"; + $sql .= ", s.nom as name"; + $sql .= ", s.rowid as socid, s.email"; + $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur"; 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"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; 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 .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = 0"; $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; @@ -160,34 +161,16 @@ $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters); $sql .= $hookmanager->resPrint; - $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"; - - // Add Group from hooks - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters); - $sql .= $hookmanager->resPrint; - $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); - print '
'; + print '
'; print ''; - print ''; - print ''; - print ''; - + print ''; if ($num) { $companystatic = new Societe($db); @@ -198,33 +181,29 @@ { $obj = $db->fetch_object($resql); - $tmpinvoice->id = $obj->rowid; - $tmpinvoice->ref = $obj->ref; - $tmpinvoice->date = $db->jdate($obj->date); - $tmpinvoice->type = $obj->type; - $tmpinvoice->total_ht = $obj->total_ht; - $tmpinvoice->total_tva = $obj->total_tva; - $tmpinvoice->total_ttc = $obj->total_ttc; - $tmpinvoice->ref_client = $obj->ref_client; - $tmpinvoice->statut = $obj->status; - $tmpinvoice->paye = $obj->paye; + $facturestatic->id = $obj->rowid; + $facturestatic->ref = $obj->ref; + $facturestatic->date = $db->jdate($obj->date); + $facturestatic->type = $obj->type; + $facturestatic->total_ht = $obj->total_ht; + $facturestatic->total_tva = $obj->total_tva; + $facturestatic->total_ttc = $obj->total_ttc; + $facturestatic->ref_client = $obj->ref_client; $companystatic->id = $obj->socid; $companystatic->name = $obj->name; $companystatic->email = $obj->email; - $companystatic->country_id = $obj->country_id; - $companystatic->country_code = $obj->country_code; $companystatic->client = 1; $companystatic->code_client = $obj->code_client; $companystatic->code_fournisseur = $obj->code_fournisseur; $companystatic->code_compta = $obj->code_compta; $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; - print ''; - print ''; + print ''; print ''; print ''; @@ -235,12 +214,16 @@ print ''; print ''; print ''; - } else { + } + else + { print ''; } print "
'; - print $langs->trans("CustomersDraftInvoices").' '; - print ''; - print ''.$num.''; - print ''; - print '
'.$langs->trans("CustomersDraftInvoices").($num ? ''.$num.'' : '').'
'; - print $tmpinvoice->getNomUrl(1, ''); - print ''; - print $companystatic->getNomUrl(1, 'customer'); + print '
'; + print $facturestatic->getNomUrl(1, ''); + print ''; + print $companystatic->getNomUrl(1, 'customer', 16); print ''.price($obj->total_ttc).'
'.$langs->trans("Total").''.price($tot_ttc).'
'.$langs->trans("NoInvoice").'

"; $db->free($resql); - } else { + } + else + { dol_print_error($db); } } @@ -250,16 +233,14 @@ */ 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"; + $sql = "SELECT f.ref, f.rowid, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier"; $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid, s.email"; - $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"; + $sql .= ", s.rowid as socid, s.email"; + $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"; - $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT; + $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = 0"; $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; @@ -273,18 +254,10 @@ { $num = $db->num_rows($resql); - print '
'; + print '
'; print ''; - print ''; - print ''; - print ''; - + print ''; if ($num) { $companystatic = new Societe($db); @@ -302,8 +275,6 @@ $facturesupplierstatic->total_ttc = $obj->total_ttc; $facturesupplierstatic->ref_supplier = $obj->ref_supplier; $facturesupplierstatic->type = $obj->type; - $facturesupplierstatic->statut = $obj->status; - $facturesupplierstatic->paye = $obj->paye; $companystatic->id = $obj->socid; $companystatic->name = $obj->name; @@ -316,11 +287,11 @@ $companystatic->code_compta = $obj->code_compta; $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; - print ''; - print ''; + print ''; print ''; print ''; @@ -331,12 +302,16 @@ print ''; print ''; print ''; - } else { + } + else + { print ''; } print "
'; - print $langs->trans("SuppliersDraftInvoices").' '; - print ''; - print ''.$num.''; - print ''; - print '
'.$langs->trans("SuppliersDraftInvoices").($num ? ''.$num.'' : '').'
'; - print $facturesupplierstatic->getNomUrl(1, ''); - print ''; - print $companystatic->getNomUrl(1, 'supplier'); + print '
'; + print $facturesupplierstatic->getNomUrl(1, '', 16); + print ''; + print $companystatic->getNomUrl(1, 'supplier', 16); print ''.price($obj->total_ttc).'
'.$langs->trans("Total").''.price($tot_ttc).'
'.$langs->trans("NoInvoice").'

"; $db->free($resql); - } else { + } + else + { dol_print_error($db); } } @@ -349,15 +324,15 @@ if (!empty($conf->facture->enabled) && $user->rights->facture->lire) { $langs->load("boxes"); - $tmpinvoice = new Facture($db); - - $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.type, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.paye, f.tms"; + $facstatic = new Facture($db); + + $sql = "SELECT f.rowid, f.ref, f.fk_statut, f.type, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.paye, f.tms"; $sql .= ", f.date_lim_reglement as datelimite"; $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid"; - $sql .= ", s.code_client, s.code_compta, s.email"; - $sql .= ", cc.rowid as country_id, cc.code as country_code"; - $sql .= ", sum(pf.amount) as am"; + $sql .= ", s.rowid as socid"; + $sql .= ", s.code_client, s.code_compta, s.email"; + $sql .= ", cc.rowid as country_id, cc.code as country_code"; + $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"; @@ -381,9 +356,8 @@ { $num = $db->num_rows($resql); $i = 0; - $othernb = 0; - - print '
'; + + print '
'; print ''; print ''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''; @@ -398,23 +372,14 @@ { $obj = $db->fetch_object($resql); - if ($i >= $max) { - $othernb += 1; - $i++; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - continue; - } - - $tmpinvoice->ref = $obj->ref; - $tmpinvoice->id = $obj->rowid; - $tmpinvoice->total_ht = $obj->total_ht; - $tmpinvoice->total_tva = $obj->total_tva; - $tmpinvoice->total_ttc = $obj->total_ttc; - $tmpinvoice->statut = $obj->status; - $tmpinvoice->paye = $obj->paye; - $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite); - $tmpinvoice->type = $obj->type; + $facturestatic->ref = $obj->ref; + $facturestatic->id = $obj->rowid; + $facturestatic->total_ht = $obj->total_ht; + $facturestatic->total_tva = $obj->total_tva; + $facturestatic->total_ttc = $obj->total_ttc; + $facturestatic->statut = $obj->fk_statut; + $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite); + $facturestatic->type = $obj->type; $thirdpartystatic->id = $obj->socid; $thirdpartystatic->name = $obj->name; @@ -433,10 +398,10 @@ print '
'.$langs->trans("BoxTitleLastCustomerBills", $max).''.$langs->trans("AmountHT").'
'; print ''; print ''; @@ -444,17 +409,17 @@ $filename = dol_sanitizeFileName($obj->ref); $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref); $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid; - print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir); + print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir); print '
'; - print $tmpinvoice->getNomUrl(1, ''); + print $facturestatic->getNomUrl(1, ''); print ''; - if ($tmpinvoice->hasDelay()) { + if ($facturestatic->hasDelay()) { print img_warning($langs->trans("Late")); } print '
'; print ''; print ''; - print $thirdpartystatic->getNomUrl(1, 'customer', 44); + print $thirdpartystatic->getNomUrl(1, 'customer', 44); print ''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''.price($obj->total_ht).''; print ''.price($obj->total_ttc).''; print ''.dol_print_date($db->jdate($obj->tms), 'day').''; - print ''.$tmpinvoice->getLibStatut(3, $obj->am).''; + print ''.$facstatic->LibStatut($obj->paye, $obj->fk_statut, 3, $obj->am).''; print ''; $total_ttc += $obj->total_ttc; @@ -463,22 +428,18 @@ $i++; } - - if ($othernb) { - print ''; - print ''; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print ''; - print "\n"; - } - } else { + } + else + { $colspan = 5; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++; print ''.$langs->trans("NoInvoice").''; } print '

'; $db->free($resql); - } else { + } + else + { dol_print_error($db); } } @@ -491,10 +452,10 @@ $langs->load("boxes"); $facstatic = new FactureFournisseur($db); - $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.libelle, ff.total_ht, ff.total_tva, ff.total_ttc, ff.tms, ff.paye"; + $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut, ff.libelle, ff.total_ht, ff.total_tva, ff.total_ttc, ff.tms, ff.paye"; $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid"; - $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email"; + $sql .= ", s.rowid as socid"; + $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email"; $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"; @@ -509,7 +470,7 @@ $sql .= $hookmanager->resPrint; $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.tms, ff.paye,"; - $sql .= " s.nom, s.rowid, s.code_fournisseur, s.code_compta_fournisseur, s.email"; + $sql .= " s.nom, s.rowid, s.code_fournisseur, s.code_compta_fournisseur"; $sql .= " ORDER BY ff.tms DESC "; $sql .= $db->plimit($max, 0); @@ -518,7 +479,7 @@ { $num = $db->num_rows($resql); - print '
'; + print '
'; print ''; print ''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''; @@ -530,27 +491,15 @@ { $i = 0; $total = $total_ttc = $totalam = 0; - $othernb = 0; - while ($i < $num) { $obj = $db->fetch_object($resql); - - if ($i >= $max) { - $othernb += 1; - $i++; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - continue; - } $facstatic->ref = $obj->ref; $facstatic->id = $obj->rowid; $facstatic->total_ht = $obj->total_ht; $facstatic->total_tva = $obj->total_tva; $facstatic->total_ttc = $obj->total_ttc; - $facstatic->statut = $obj->status; - $facstatic->paye = $obj->paye; $thirdpartystatic->id = $obj->socid; $thirdpartystatic->name = $obj->name; @@ -564,37 +513,33 @@ $thirdpartystatic->code_compta = ''; $thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur; - print ''; - print ''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''; print ''; print ''; - print ''; + print ''; print ''; $total += $obj->total_ht; $total_ttc += $obj->total_ttc; $totalam += $obj->am; $i++; } - - if ($othernb) { - print ''; - print ''; - print "\n"; - } - } else { + } + else + { $colspan = 5; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++; print ''; } print '
'.$langs->trans("BoxTitleLastSupplierBills", $max).''.$langs->trans("AmountHT").'
'; + print '
'; print $facstatic->getNomUrl(1, ''); print ''; - print $thirdpartystatic->getNomUrl(1, 'supplier'); + print ''; + print $thirdpartystatic->getNomUrl(1, 'supplier', 44); print ''.price($obj->total_ht).''.price($obj->total_ttc).''.dol_print_date($db->jdate($obj->tms), 'day').''.$facstatic->getLibStatut(3).''.$facstatic->LibStatut($obj->paye, $obj->fk_statut, 3).'
'; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print '
'.$langs->trans("NoInvoice").'

'; - } else { + } + else + { dol_print_error($db); } } @@ -607,9 +552,9 @@ include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; $langs->load("boxes"); - $donationstatic = new Don($db); - - $sql = "SELECT d.rowid, d.lastname, d.firstname, d.societe, d.datedon as date, d.tms as dm, d.amount, d.fk_statut as status"; + $donationstatic = new Don($db); + + $sql = "SELECT d.rowid, d.lastname, d.firstname, d.societe, d.datedon as date, d.tms as dm, d.amount, d.fk_statut"; $sql .= " FROM ".MAIN_DB_PREFIX."don as d"; $sql .= " WHERE d.entity IN (".getEntity('donation').")"; // Add where from hooks @@ -623,19 +568,19 @@ $result = $db->query($sql); if ($result) { + $var = false; $num = $db->num_rows($result); $i = 0; - $othernb = 0; - - print '
'; + + print '
'; print ''; print ''; print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; print ''; if ($num) { @@ -644,49 +589,33 @@ while ($i < $num && $i < $max) { $objp = $db->fetch_object($result); - - if ($i >= $max) { - $othernb += 1; - $i++; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - continue; - } $donationstatic->id = $objp->rowid; $donationstatic->ref = $objp->rowid; $donationstatic->lastname = $objp->lastname; $donationstatic->firstname = $objp->firstname; - $donationstatic->date = $objp->date; - $donationstatic->statut = $objp->status; - $donationstatic->status = $objp->status; $label = $donationstatic->getFullName($langs); if ($objp->societe) $label .= ($label ? ' - ' : '').$objp->societe; - print ''; + print ''; print ''; print ''; print ''; print ''; - print ''; + print ''; print ''; $i++; } - - if ($othernb) { - print ''; - print ''; - print "\n"; - } - } else { + } + else + { print ''; } print '
'.$langs->trans("BoxTitleLastModifiedDonations", $max).''.$langs->trans("AmountTTC").''.$langs->trans("DateModificationShort").' '.$langs->trans("AmountTTC").''.$langs->trans("DateModificationShort").' 
'.$donationstatic->getNomUrl(1).''.$label.''.price($objp->amount).''.dol_print_date($db->jdate($objp->dm), 'day').''.$donationstatic->getLibStatut(3).''.$donationstatic->LibStatut($objp->fk_statut, 3).'
'; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print '
'.$langs->trans("None").'

'; - } else dol_print_error($db); + } + else dol_print_error($db); } /** @@ -718,7 +647,7 @@ { $num = $db->num_rows($resql); - print '
'; + print '
'; print ''; print ''; print ''; @@ -731,28 +660,17 @@ { $i = 0; $tot_ttc = 0; - $othernb = 0; - while ($i < $num) { $obj = $db->fetch_object($resql); - - if ($i >= $max) { - $othernb += 1; - $i++; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - continue; - } $chargestatic->id = $obj->rowid; $chargestatic->ref = $obj->rowid; $chargestatic->label = $obj->label; $chargestatic->paye = $obj->paye; - $chargestatic->status = $obj->paye; print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -763,25 +681,21 @@ $i++; } - if ($othernb) { - print ''; - print ''; - print "\n"; - } - print ''; print ''; print ''; print ''; print ''; - } else { + } + else + { print ''; } print "
'.$langs->trans("ContributionsToPay").($num ? ' '.$num.'' : '').'
'.$chargestatic->getNomUrl(1).''.$chargestatic->getNomUrl(1).''.dol_print_date($db->jdate($obj->date_ech), 'day').''.price($obj->amount).''.price($obj->sumpaid).'
'; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print '
'.$langs->trans("Total").''.price($tot_ttc).' 
'.$langs->trans("None").'

"; $db->free($resql); - } else { + } + else + { dol_print_error($db); } } @@ -797,9 +711,9 @@ $sql = "SELECT sum(f.total) as tot_fht, sum(f.total_ttc) as tot_fttc"; $sql .= ", s.nom as name, s.email"; - $sql .= ", s.rowid as socid"; - $sql .= ", s.code_client, s.code_compta"; - $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.tva as total_tva, c.total_ttc,"; + $sql .= ", s.rowid as socid"; + $sql .= ", s.code_client, s.code_compta"; + $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut, c.total_ht, c.tva as 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"; @@ -810,7 +724,7 @@ $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; - $sql .= " AND c.fk_statut = ".Commande::STATUS_CLOSED; + $sql .= " AND c.fk_statut = 3"; $sql .= " AND c.facture = 0"; // Add where from hooks $parameters = array(); @@ -827,19 +741,11 @@ if ($num) { $i = 0; - $othernb = 0; - - print '
'; + + print '
'; print ''; - print ""; - print ''; - + print ''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''; print ''; print ''; @@ -851,14 +757,6 @@ while ($i < $num) { $obj = $db->fetch_object($resql); - - if ($i >= $max) { - $othernb += 1; - $i++; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - continue; - } $societestatic->id = $obj->socid; $societestatic->name = $obj->name; @@ -873,8 +771,6 @@ $commandestatic->id = $obj->rowid; $commandestatic->ref = $obj->ref; - $commandestatic->statut = $obj->status; - $commandestatic->billed = $obj->facture; print ''; print ''; - print ''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''; print ''; print ''; - print ''; + print ''; print ''; $tot_ht += $obj->total_ht; $tot_ttc += $obj->total_ttc; @@ -910,14 +806,6 @@ $i++; } - if ($othernb) { - print ''; - print ''; - print "\n"; - } - print ''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''; print ''; @@ -927,7 +815,9 @@ print '
'; - print $langs->trans("OrdersDeliveredToBill").' '; - print ''; - print ''.$num.''; - print ''; - print ''.$langs->trans("OrdersDeliveredToBill").' '.$num.''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("ToBill").'
'; @@ -895,13 +791,13 @@ print ''; - print $societestatic->getNomUrl(1, 'customer'); + print ''; + print $societestatic->getNomUrl(1, 'customer', 44); print ''.price($obj->total_ht).''.price($obj->total_ttc).''.price($obj->total_ttc - $obj->tot_fttc).''.$commandestatic->getLibStatut(3).''.$commandestatic->LibStatut($obj->fk_statut, $obj->facture, 3).'
'; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print '
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToBill").': '.price($tot_tobill).') '.price($tot_ht).''.price($tot_ttc).'

'; } $db->free($resql); - } else { + } + else + { dol_print_error($db); } } @@ -937,19 +827,19 @@ */ 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"; + $facstatic = new Facture($db); + + $sql = "SELECT f.rowid, f.ref, f.fk_statut, f.datef, f.type, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.paye, f.tms"; $sql .= ", f.date_lim_reglement as datelimite"; $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid, s.email"; - $sql .= ", s.code_client, s.code_compta"; - $sql .= ", cc.rowid as country_id, cc.code as country_code"; - $sql .= ", sum(pf.amount) as am"; + $sql .= ", s.rowid as socid, s.email"; + $sql .= ", s.code_client, s.code_compta"; + $sql .= ", cc.rowid as country_id, cc.code as country_code"; + $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"; - $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED; + $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; $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; @@ -967,19 +857,10 @@ { $num = $db->num_rows($resql); $i = 0; - $othernb = 0; print '
'; print ''; - - print ''; - print ''; - + print ''; print ''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''; print ''; @@ -994,23 +875,14 @@ { $obj = $db->fetch_object($resql); - if ($i >= $max) { - $othernb += 1; - $i++; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - continue; - } - - $tmpinvoice->ref = $obj->ref; - $tmpinvoice->id = $obj->rowid; - $tmpinvoice->total_ht = $obj->total_ht; - $tmpinvoice->total_tva = $obj->total_tva; - $tmpinvoice->total_ttc = $obj->total_ttc; - $tmpinvoice->type = $obj->type; - $tmpinvoice->statut = $obj->status; - $tmpinvoice->paye = $obj->paye; - $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite); + $facturestatic->ref = $obj->ref; + $facturestatic->id = $obj->rowid; + $facturestatic->total_ht = $obj->total_ht; + $facturestatic->total_tva = $obj->total_tva; + $facturestatic->total_ttc = $obj->total_ttc; + $facturestatic->type = $obj->type; + $facturestatic->statut = $obj->fk_statut; + $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite); $societestatic->id = $obj->socid; $societestatic->name = $obj->name; @@ -1028,10 +900,10 @@ print '
'; - print $langs->trans("BillsCustomersUnpaid", $num).' '; - print ''; - print ''.$num.''; - print ''; - print '
'.$langs->trans("BillsCustomersUnpaid", $num).' '.$num.''.$langs->trans("DateDue").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").'
'; print ''; print ''; @@ -1039,18 +911,18 @@ $filename = dol_sanitizeFileName($obj->ref); $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref); $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid; - print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir); + print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir); print '
'; - print $tmpinvoice->getNomUrl(1, ''); + print $facturestatic->getNomUrl(1, ''); print ''; - if ($tmpinvoice->hasDelay()) { + if ($facturestatic->hasDelay()) { print img_warning($langs->trans("Late")); } print '
'; print ''; - print ''; - print $societestatic->getNomUrl(1, 'customer'); + print ''; + print $societestatic->getNomUrl(1, 'customer', 44); print ''; print ''.dol_print_date($db->jdate($obj->datelimite), 'day').''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''.price($obj->total_ht).''; print ''.price($obj->total_ttc).''; print ''.price($obj->am).''; - print ''.$tmpinvoice->getLibStatut(3, $obj->am).''; + print ''.$facstatic->LibStatut($obj->paye, $obj->fk_statut, 3, $obj->am).''; print ''; $total_ttc += $obj->total_ttc; @@ -1058,16 +930,6 @@ $totalam += $obj->am; $i++; - } - - if ($othernb) { - $colspan = 6; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++; - print ''; - print ''; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print ''; - print "\n"; } print ''.$langs->trans("Total").'   ('.$langs->trans("RemainderToTake").': '.price($total_ttc - $totalam).') '; @@ -1077,31 +939,35 @@ print ''.price($totalam).''; print ' '; print ''; - } else { + } + else + { $colspan = 6; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++; print ''.$langs->trans("NoInvoice").''; } print '

'; $db->free($resql); - } else { + } + else + { dol_print_error($db); } } /* - * Unpaid supplier invoices + * Unpayed supplier invoices */ 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"; + $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut, ff.libelle as label, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye"; $sql .= ", ff.date_lim_reglement"; $sql .= ", s.nom as name"; - $sql .= ", s.rowid as socid, s.email"; - $sql .= ", s.code_client, s.code_compta"; - $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; + $sql .= ", s.rowid as socid, s.email"; + $sql .= ", s.code_client, s.code_compta"; + $sql .= ", s.code_fournisseur, s.code_compta_fournisseur"; $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"; @@ -1109,7 +975,7 @@ $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; + $sql .= " AND ff.fk_statut = 1"; 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 @@ -1117,7 +983,7 @@ $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters); $sql .= $hookmanager->resPrint; - $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.type, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.paye, ff.date_lim_reglement,"; + $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.paye, ff.date_lim_reglement,"; $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur"; $sql .= " ORDER BY ff.date_lim_reglement ASC"; @@ -1125,21 +991,10 @@ if ($resql) { $num = $db->num_rows($resql); - $othernb = 0; print '
'; print ''; - - print ''; - print ''; - + print ''; print ''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''; print ''; @@ -1155,22 +1010,11 @@ { $obj = $db->fetch_object($resql); - if ($i >= $max) { - $othernb += 1; - $i++; - $total += $obj->total_ht; - $total_ttc += $obj->total_ttc; - continue; - } - $facstatic->ref = $obj->ref; $facstatic->id = $obj->rowid; - $facstatic->type = $obj->type; $facstatic->total_ht = $obj->total_ht; $facstatic->total_tva = $obj->total_tva; $facstatic->total_ttc = $obj->total_ttc; - $facstatic->statut = $obj->status; - $facstatic->paye = $obj->paye; $societestatic->id = $obj->socid; $societestatic->name = $obj->name; @@ -1182,30 +1026,20 @@ $societestatic->code_compta = $obj->code_compta; $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur; - print ''; - print ''; + print ''; print ''; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''; print ''; print ''; - print ''; + print ''; print ''; $total += $obj->total_ht; $total_ttc += $obj->total_ttc; $totalam += $obj->am; $i++; - } - - if ($othernb) { - $colspan = 6; - if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++; - print ''; - print ''; - print "\n"; } print ''; @@ -1215,13 +1049,17 @@ print ''; print ''; print ''; - } else { + } + else + { $colspan = 6; if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++; print ''; } print '
'; - print $langs->trans("BillsSuppliersUnpaid", $num).' '; - print ''; - // TODO: "impayees.php" looks very outdatetd and should be set to deprecated or directly remove in the next version - // - print ''.$num.''; - print ''; - print '
'.$langs->trans("BillsSuppliersUnpaid", $num).' '.$num.''.$langs->trans("DateDue").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").'
'; + print '
'; print $facstatic->getNomUrl(1, ''); print ''.$societestatic->getNomUrl(1, 'supplier').''.$societestatic->getNomUrl(1, 'supplier', 44).''.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').''.price($obj->total_ht).''.price($obj->total_ttc).''.price($obj->am).''.$facstatic->getLibStatut(3, $obj->am).''.$facstatic->LibStatut($obj->paye, $obj->fk_statut, 3).'
'; - print ''.$langs->trans("More").'... ('.$othernb.')'; - print '
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToPay").': '.price($total_ttc - $totalam).') '.price($totalam).' 
'.$langs->trans("NoInvoice").'

'; - } else { + } + else + { dol_print_error($db); } } @@ -1232,7 +1070,7 @@ $resql = 0; if ($resql) { - print '
'; + print '
'; print ''; print ''.$langs->trans("TasksToDo").''; print "\n"; --- /tmp/dsg/dolibarr/htdocs/compta/github_paiement.php +++ /tmp/dsg/dolibarr/htdocs/compta/client_paiement.php @@ -47,7 +47,7 @@ $paymentnum = GETPOST('num_paiement', 'alpha'); $socid = GETPOST('socid', 'int'); -$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); @@ -61,7 +61,7 @@ // Security check if ($user->socid > 0) { - $socid = $user->socid; + $socid = $user->socid; } $object = new Facture($db); @@ -90,111 +90,112 @@ { 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')); - $paiement_id = 0; - $totalpayment = 0; + $error = 0; + + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); + $paiement_id = 0; + $totalpayment = 0; $multicurrency_totalpayment = 0; - $atleastonepaymentnotnull = 0; + $atleastonepaymentnotnull = 0; $formquestion = array(); $i = 0; - // 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) - { + // 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) != '') - { - $cursorfacid = substr($key, 7); - $amounts[$cursorfacid] = price2num(GETPOST($key)); - $totalpayment = $totalpayment + $amounts[$cursorfacid]; - if (!empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++; - $result = $tmpinvoice->fetch($cursorfacid); - if ($result <= 0) dol_print_error($db); - $amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement()); - if ($amounts[$cursorfacid]) - { - // Check amount - 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)) - { - $langs->load("errors"); - //$error++; - setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); - } - } - - $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => $_POST[$key]); - } elseif (substr($key, 0, 21) == 'multicurrency_amount_') + { + $cursorfacid = substr($key, 7); + $amounts[$cursorfacid] = price2num(trim(GETPOST($key))); + $totalpayment = $totalpayment + $amounts[$cursorfacid]; + if (!empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++; + $result = $tmpinvoice->fetch($cursorfacid); + if ($result <= 0) dol_print_error($db); + $amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement()); + if ($amounts[$cursorfacid]) + { + // Check amount + 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)) + { + $langs->load("errors"); + //$error++; + setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); + } + } + + $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => $_POST[$key]); + } + 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++; - $result = $tmpinvoice->fetch($cursorfacid); - if ($result <= 0) dol_print_error($db); - $multicurrency_amountsresttopay[$cursorfacid] = price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1)); - if ($multicurrency_amounts[$cursorfacid]) - { - // Check amount - 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)) - { - $langs->load("errors"); - //$error++; - setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); - } - } - - $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => GETPOST($key, 'int')); + $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key))); + $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid]; + if (!empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++; + $result = $tmpinvoice->fetch($cursorfacid); + if ($result <= 0) dol_print_error($db); + $multicurrency_amountsresttopay[$cursorfacid] = price2num($tmpinvoice->multicurrency_total_ttc - $tmpinvoice->getSommePaiement(1)); + if ($multicurrency_amounts[$cursorfacid]) + { + // Check amount + 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)) + { + $langs->load("errors"); + //$error++; + setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings'); + } + } + + $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => GETPOST($key, 'int')); } - } - - // Check parameters - if (!GETPOST('paiementcode')) - { - setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('PaymentMode')), null, 'errors'); - $error++; - } - - if (!empty($conf->banque->enabled)) - { - // If bank module is on, account is required to enter a payment - if (GETPOST('accountid') <= 0) - { - setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors'); - $error++; - } - } - - if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) - { - setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->trans('PaymentAmount')), null, 'errors'); - $error++; - } - - if (empty($datepaye)) - { - setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('Date')), null, 'errors'); - $error++; - } + } + + // Check parameters + if (!GETPOST('paiementcode')) + { + setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('PaymentMode')), null, 'errors'); + $error++; + } + + if (!empty($conf->banque->enabled)) + { + // If bank module is on, account is required to enter a payment + if (GETPOST('accountid') <= 0) + { + setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors'); + $error++; + } + } + + if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull)) + { + setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->trans('PaymentAmount')), null, 'errors'); + $error++; + } + + 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) { setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors'); - $error++; + $error++; } } @@ -203,11 +204,11 @@ */ if ($action == 'add_paiement') { - if ($error) - { - $action = 'create'; - } - // The next of this action is displayed at the page's bottom. + if ($error) + { + $action = 'create'; + } + // Le reste propre a cette action s'affiche en bas de page. } /* @@ -215,103 +216,107 @@ */ if ($action == 'confirm_paiement' && $confirm == 'yes') { - $error = 0; - - $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); - - $db->begin(); - - $thirdparty = new Societe($db); - 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 - { - $tmpinvoice = new Facture($db); - $tmpinvoice->fetch($key); - 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 - { - $tmpinvoice = new Facture($db); - $tmpinvoice->fetch($key); - if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE) - { - $newvalue = price2num($value, 'MT'); - $multicurrency_amounts[$key] = - abs($newvalue); - } - } - - if (!empty($conf->banque->enabled)) - { - // If the bank module is active, an account is required to input a payment - if (GETPOST('accountid', 'int') <= 0) - { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors'); - $error++; - } - } - - // Creation of payment line - $paiement = new Paiement($db); - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id - $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching - $paiement->paiementid = dol_getIdFromCode($db, GETPOST('paiementcode'), 'c_paiement', 'code', 'id', 1); - $paiement->num_payment = GETPOST('num_paiement', 'alpha'); - $paiement->note_private = GETPOST('comment', 'alpha'); - - 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) - { - setEventMessages($paiement->error, $paiement->errors, 'errors'); - $error++; - } - } - - if (!$error) - { - $label = '(CustomerInvoicePayment)'; - 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) - { - setEventMessages($paiement->error, $paiement->errors, 'errors'); - $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) - { - $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 ($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 { - $db->rollback(); - } + $error = 0; + + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); + + $db->begin(); + + $thirdparty = new Societe($db); + 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 + { + $tmpinvoice = new Facture($db); + $tmpinvoice->fetch($key); + 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 + { + $tmpinvoice = new Facture($db); + $tmpinvoice->fetch($key); + if ($tmpinvoice->type == Facture::TYPE_CREDIT_NOTE) + { + $newvalue = price2num($value, 'MT'); + $multicurrency_amounts[$key] = - abs($newvalue); + } + } + + if (!empty($conf->banque->enabled)) + { + // Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement + if (GETPOST('accountid', 'int') <= 0) + { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors'); + $error++; + } + } + + // Creation of payment line + $paiement = new Paiement($db); + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id + $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching + $paiement->paiementid = dol_getIdFromCode($db, GETPOST('paiementcode'), 'c_paiement', 'code', 'id', 1); + $paiement->num_payment = GETPOST('num_paiement', 'alpha'); + $paiement->note_private = GETPOST('comment', 'alpha'); + $paiement->num_paiement = $paiement->num_payment; // For bacward compatibility + $paiement->note = $paiement->note_private; // For bacward compatibility + + 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) + { + setEventMessages($paiement->error, $paiement->errors, 'errors'); + $error++; + } + } + + if (!$error) + { + $label = '(CustomerInvoicePayment)'; + 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) + { + setEventMessages($paiement->error, $paiement->errors, 'errors'); + $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) + { + $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 ($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 + { + $db->rollback(); + } } } @@ -469,77 +474,79 @@ print ''; print ''; - print dol_get_fiche_head(); + dol_fiche_head(); print '
'; - // Third party - print '\n"; - - // Date payment - print ''; - - // Payment mode - print '\n"; - print ''; - - // Bank account - print ''; - if (!empty($conf->banque->enabled)) - { - if ($facture->type != 2) print ''; - if ($facture->type == 2) print ''; - print ''; - } else { - print ''; - } - print "\n"; - - // Bank check number - print ''; - print ''; - - // Check transmitter - print ''; - print ''; - - // Bank name - print ''; - print ''; + // Third party + print '\n"; + + // Date payment + print ''; + + // Payment mode + print '\n"; + print ''; + + // Bank account + print ''; + if (!empty($conf->banque->enabled)) + { + if ($facture->type != 2) print ''; + if ($facture->type == 2) print ''; + print ''; + } + else + { + print ''; + } + print "\n"; + + // Cheque number + print ''; + print ''; + + // Check transmitter + print ''; + print ''; + + // Bank name + print ''; + print ''; // Comments print ''; print ''; - - print '
'.$langs->trans('Company').''.$facture->thirdparty->getNomUrl(4)."
'.$langs->trans('Date').''; - $datepayment = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - $datepayment = ($datepayment == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $datepayment); - print $form->selectDate($datepayment, '', '', '', 0, "add_paiement", 1, 1, 0, '', '', $facture->date); - print '
'.$langs->trans('PaymentMode').''; - $form->select_types_paiements((GETPOST('paiementcode') ?GETPOST('paiementcode') : $facture->mode_reglement_code), 'paiementcode', '', 2); - print "
'.$langs->trans('AccountToCredit').''.$langs->trans('AccountToDebit').''; - $form->select_comptes($accountid, 'accountid', 0, '', 2); - print ' 
'.$langs->trans('Numero'); - print ' ('.$langs->trans("ChequeOrTransferNumber").')'; - print '
'.$langs->trans('CheckTransmitter'); - print ' ('.$langs->trans("ChequeMaker").')'; - print '
'.$langs->trans('Bank'); - print ' ('.$langs->trans("ChequeBank").')'; - print '
'.$langs->trans('Company').''.$facture->thirdparty->getNomUrl(4)."
'.$langs->trans('Date').''; + $datepayment = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $datepayment = ($datepayment == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $datepayment); + print $form->selectDate($datepayment, '', '', '', 0, "add_paiement", 1, 1, 0, '', '', $facture->date); + print '
'.$langs->trans('PaymentMode').''; + $form->select_types_paiements((GETPOST('paiementcode') ?GETPOST('paiementcode') : $facture->mode_reglement_code), 'paiementcode', '', 2); + print "
'.$langs->trans('AccountToCredit').''.$langs->trans('AccountToDebit').''; + $form->select_comptes($accountid, 'accountid', 0, '', 2); + print ' 
'.$langs->trans('Numero'); + print ' ('.$langs->trans("ChequeOrTransferNumber").')'; + print '
'.$langs->trans('CheckTransmitter'); + print ' ('.$langs->trans("ChequeMaker").')'; + print '
'.$langs->trans('Bank'); + print ' ('.$langs->trans("ChequeBank").')'; + print '
'.$langs->trans('Comments').''; - print '
'; - - print dol_get_fiche_end(); - - - /* + print ''; + + print ''; + + dol_fiche_end(); + + + /* * 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'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f'; + $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'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f'; $sql .= ' WHERE f.entity IN ('.getEntity('facture').')'; - $sql .= ' AND (f.fk_soc = '.$facture->socid; + $sql .= ' AND (f.fk_soc = '.$facture->socid; // Can pay invoices of all child of parent company if (!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS) && !empty($facture->thirdparty->parent)) { $sql .= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')'; @@ -548,23 +555,25 @@ if (!empty($conf->global->FACTURE_PAYMENTS_ON_SUBSIDIARY_COMPANIES)) { $sql .= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->id.')'; } - $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) - { - $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 - } - // Sort invoices by date and serial number: the older one comes first - $sql .= ' ORDER BY f.datef ASC, f.ref ASC'; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - if ($num > 0) - { + $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) + { + $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 + } + // Sort invoices by date and serial number: the older one comes first + $sql .= ' ORDER BY f.datef ASC, f.ref ASC'; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num > 0) + { $arraytitle = $langs->trans('Invoice'); if ($facture->type == 2) $arraytitle = $langs->trans("CreditNotes"); $alreadypayedlabel = $langs->trans('Received'); @@ -574,57 +583,55 @@ $multicurrencyremaindertopay = $langs->trans('MulticurrencyRemainderToTake'); if ($facture->type == 2) { $remaindertopay = $langs->trans("RemainderToPayBack"); $multicurrencyremaindertopay = $langs->trans("MulticurrencyRemainderToPayBack"); } - $i = 0; - //print ''; - print '
'; - - print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table - print ''; - - print ''; - print ''; - print ''; - print ''; - if (!empty($conf->multicurrency->enabled)) { - print ''; - print ''; - print ''; - print ''; - print ''; - } - print ''; - print ''; - print ''; - print ''; - - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $facture, $action); // Note that $action and $object may have been modified by hook - - print ''; - print "\n"; - - $total = 0; - $totalrecu = 0; - $totalrecucreditnote = 0; - $totalrecudeposits = 0; - - while ($i < $num) - { - $objp = $db->fetch_object($resql); - - $sign = 1; - if ($facture->type == Facture::TYPE_CREDIT_NOTE) $sign = -1; + $i = 0; + //print ''; + print ''; + print ''; // Autofilled + print ''; + print "\n"; + } + print "
'.$arraytitle.''.$langs->trans('Date').''.$langs->trans('DateMaxPayment').''.$langs->trans('Currency').''.$langs->trans('MulticurrencyAmountTTC').''.$multicurrencyalreadypayedlabel.''.$multicurrencyremaindertopay.''.$langs->trans('MulticurrencyPaymentAmount').''.$langs->trans('AmountTTC').''.$alreadypayedlabel.''.$remaindertopay.''.$langs->trans('PaymentAmount').' 
'; + print '
'; + print ''; + + print ''; + print ''; + print ''; + print ''; + if (!empty($conf->multicurrency->enabled)) { + print ''; + print ''; + print ''; + print ''; + print ''; + } + print ''; + print ''; + print ''; + print ''; + + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $facture, $action); // Note that $action and $object may have been modified by hook + + print ''; + print "\n"; + + $total = 0; + $totalrecu = 0; + $totalrecucreditnote = 0; + $totalrecudeposits = 0; + + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + $sign = 1; + if ($facture->type == Facture::TYPE_CREDIT_NOTE) $sign = -1; $soc = new Societe($db); $soc->fetch($objp->socid); - $invoice = new Facture($db); - $invoice->fetch($objp->facid); - $paiement = $invoice->getSommePaiement(); - $creditnotes = $invoice->getSumCreditNotesUsed(); - $deposits = $invoice->getSumDepositsUsed(); - $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT'); - $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT'); + $invoice = new Facture($db); + $invoice->fetch($objp->facid); + $paiement = $invoice->getSommePaiement(); + $creditnotes = $invoice->getSumCreditNotesUsed(); + $deposits = $invoice->getSumDepositsUsed(); + $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT'); + $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT'); // Multicurrency Price if (!empty($conf->multicurrency->enabled)) { @@ -632,209 +639,217 @@ $multicurrency_creditnotes = $invoice->getSumCreditNotesUsed(1); $multicurrency_deposits = $invoice->getSumDepositsUsed(1); $multicurrency_alreadypayed = price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits, 'MT'); - $multicurrency_remaintopay = price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits, 'MT'); + $multicurrency_remaintopay = price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits, 'MT'); } print ''; print '\n"; - - // Date - print '\n"; - - // Due date - if ($objp->dlr > 0) - { - print ''; - } else { - print ''; - } - - // Currency - if (!empty($conf->multicurrency->enabled)) print '\n"; + print $invoice->getNomUrl(1, ''); + if ($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' '; + print "\n"; + + // Date + print '\n"; + + // Due date + if ($objp->dlr > 0) + { + print ''; + } + else + { + print ''; + } + + // Currency + if (!empty($conf->multicurrency->enabled)) print '\n"; // Multicurrency Price if (!empty($conf->multicurrency->enabled)) { - print ''; - - // Multicurrency Price + print ''; + + // Multicurrency Price print ''; - - // Multicurrency remain to pay - print ''; - - print '"; + print ''; + + // Multicurrency remain to pay + print ''; + + print '"; } // Price - print ''; - - // Received + already paid - print ''; - - // Remain to take or to pay back - print ''; - //$test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits)); - - // Amount - print ''; + + // Received or paid back + print ''; + + // Remain to take or to pay back + print ''; + //$test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits)); + + // Amount + print '"; - - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook - - // Warning - print ''; - - print "\n"; - - $total += $objp->total; - $total_ttc += $objp->total_ttc; - $totalrecu += $paiement; - $totalrecucreditnote += $creditnotes; - $totalrecudeposits += $deposits; - $i++; - } - - if ($i > 1) - { - // Print total - print ''; - print ''; - if (!empty($conf->multicurrency->enabled)) { - print ''; - print ''; - print ''; - print ''; - print ''; - } + print ''; + print ''; + } + else + { + print ''; + print ''; + } + print ""; + + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook + + // Warning + print ''; + + print "\n"; + + $total += $objp->total; + $total_ttc += $objp->total_ttc; + $totalrecu += $paiement; + $totalrecucreditnote += $creditnotes; + $totalrecudeposits += $deposits; + $i++; + } + + if ($i > 1) + { + // Print total + print ''; + print ''; + if (!empty($conf->multicurrency->enabled)) { + print ''; + print ''; + print ''; + print ''; + print ''; + } print ''; - print ''; - print ''; - print ''; // Autofilled - print ''; - print "\n"; - } - print "
'.$arraytitle.''.$langs->trans('Date').''.$langs->trans('DateMaxPayment').''.$langs->trans('Currency').''.$langs->trans('MulticurrencyAmountTTC').''.$multicurrencyalreadypayedlabel.''.$multicurrencyremaindertopay.''.$langs->trans('MulticurrencyPaymentAmount').''.$langs->trans('AmountTTC').''.$alreadypayedlabel.''.$remaindertopay.''.$langs->trans('PaymentAmount').' 
'; - print $invoice->getNomUrl(1, ''); - if ($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' '; - print "'.dol_print_date($db->jdate($objp->df), 'day')."'; - print dol_print_date($db->jdate($objp->dlr), 'day'); - - if ($invoice->hasDelay()) - { - print img_warning($langs->trans('Late')); - } - - print ''.$objp->multicurrency_code."'.dol_print_date($db->jdate($objp->df), 'day')."'; + print dol_print_date($db->jdate($objp->dlr), 'day'); + + if ($invoice->hasDelay()) + { + print img_warning($langs->trans('Late')); + } + + print ''.$objp->multicurrency_code."'; - if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $objp->multicurrency_total_ttc); - print ''; + if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $objp->multicurrency_total_ttc); + print ''; 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); + print price($sign * $multicurrency_payment); + if ($multicurrency_creditnotes) print '+'.price($multicurrency_creditnotes); + if ($multicurrency_deposits) print '+'.price($multicurrency_deposits); } - print ''; - if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $multicurrency_remaintopay); - print ''; - - // Add remind multicurrency amount - $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)) - print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'"); - print ''; - print ''; - } else { - print ''; - print ''; - } - } - print "'; + if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency) print price($sign * $multicurrency_remaintopay); + print ''; + + // Add remind multicurrency amount + $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)) + print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'"); + print ''; + print ''; + } + else + { + print ''; + print ''; + } + } + print "'.price($sign * $objp->total_ttc).''.price($sign * $paiement); - if ($creditnotes) print '+'.price($creditnotes).''; - if ($deposits) print '+'.price($deposits).''; - print ''.price($sign * $remaintopay).''; - - // Add remind amount - $namef = 'amount_'.$objp->facid; - $nameRemain = 'remain_'.$objp->facid; - - if ($action != 'add_paiement') - { - if (!empty($conf->use_javascript_ajax)) + print ''.price($sign * $objp->total_ttc).''.price($sign * $paiement); + if ($creditnotes) print '+'.price($creditnotes); + if ($deposits) print '+'.price($deposits); + print ''.price($sign * $remaintopay).''; + + // Add remind amount + $namef = 'amount_'.$objp->facid; + $nameRemain = 'remain_'.$objp->facid; + + 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 ''; - print ''; - } else { - print ''; - print ''; - } - print "'; - //print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."
"; - 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]))) - { - print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay")); - } - print '
'.$langs->trans('TotalTTC').''; + //print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."
"; + 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]))) + { + print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay")); + } + print '
'.$langs->trans('TotalTTC').''.price($sign * $total_ttc).''.price($sign * $totalrecu); - if ($totalrecucreditnote) print '+'.price($totalrecucreditnote); - if ($totalrecudeposits) print '+'.price($totalrecudeposits); - print ''.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).' 
"; - print "\n"; - } - $db->free($resql); - } else { - dol_print_error($db); - } - - - // Save button - if ($action != 'add_paiement') + print '
'.price($sign * $totalrecu); + if ($totalrecucreditnote) print '+'.price($totalrecucreditnote); + if ($totalrecudeposits) print '+'.price($totalrecudeposits); + print ''.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).' 
"; + //print "\n"; + } + $db->free($resql); + } + else { - $checkboxlabel = $langs->trans("ClosePaidInvoicesAutomatically"); - 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'); - - print '
'; - print ' '.$checkboxlabel; - /*if (! empty($conf->prelevement->enabled)) + dol_print_error($db); + } + + + // Bouton Enregistrer + if ($action != 'add_paiement') + { + $checkboxlabel = $langs->trans("ClosePaidInvoicesAutomatically"); + 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'); + + print '
'; + print ' '.$checkboxlabel; + /*if (! empty($conf->prelevement->enabled)) { $langs->load("withdrawals"); if (! empty($conf->global->WITHDRAW_DISABLE_AUTOCREATE_ONPAYMENTS)) print '
'.$langs->trans("IfInvoiceNeedOnWithdrawPaymentWontBeClosed"); }*/ - print '


'; - print '
'; - } - - // Form to confirm payment - if ($action == 'add_paiement') - { - $preselectedchoice = $addwarning ? 'no' : 'yes'; - - print '
'; - if (!empty($totalpayment)) $text = $langs->trans('ConfirmCustomerPayment', $totalpayment, $langs->trans("Currency".$conf->currency)); + print '


'; + print '
'; + } + + // Form to confirm payment + if ($action == 'add_paiement') + { + $preselectedchoice = $addwarning ? 'no' : 'yes'; + + print '
'; + if (!empty($totalpayment)) $text = $langs->trans('ConfirmCustomerPayment', $totalpayment, $langs->trans("Currency".$conf->currency)); if (!empty($multicurrency_totalpayment)) { $text .= '
'.$langs->trans('ConfirmCustomerPayment', $multicurrency_totalpayment, $langs->trans("paymentInInvoiceCurrency")); } - if (GETPOST('closepaidinvoices')) - { - $text .= '
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); - print ''; - } - print $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type, $langs->trans('ReceivedCustomersPayments'), $text, 'confirm_paiement', $formquestion, $preselectedchoice); - } - - print "\n"; - } + if (GETPOST('closepaidinvoices')) + { + $text .= '
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); + print ''; + } + print $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type, $langs->trans('ReceivedCustomersPayments'), $text, 'confirm_paiement', $formquestion, $preselectedchoice); + } + + print "\n"; + } } @@ -843,62 +858,62 @@ */ 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'; - - $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'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id'; - $sql .= ', '.MAIN_DB_PREFIX.'facture as f'; - $sql .= ' WHERE p.fk_facture = f.rowid'; - $sql .= ' AND f.entity IN ('.getEntity('invoice').')'; - if ($socid) - { - $sql .= ' AND f.fk_soc = '.$socid; - } - - $sql .= ' ORDER BY '.$sortfield.' '.$sortorder; - $sql .= $db->plimit($limit + 1, $offset); - $resql = $db->query($sql); - - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - - print_barre_liste($langs->trans('Payments'), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num); - print ''; - print ''; - print_liste_field_titre('Invoice', $_SERVER["PHP_SELF"], 'f.ref', '', '', '', $sortfield, $sortorder); - print_liste_field_titre('Date', $_SERVER["PHP_SELF"], 'p.datep', '', '', '', $sortfield, $sortorder); - print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'c.libelle', '', '', '', $sortfield, $sortorder); - print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], 'p.amount', '', '', '', $sortfield, $sortorder, 'right '); + 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'; + + $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'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id'; + $sql .= ', '.MAIN_DB_PREFIX.'facture as f'; + $sql .= ' WHERE p.fk_facture = f.rowid'; + $sql .= ' AND f.entity IN ('.getEntity('invoice').')'; + if ($socid) + { + $sql .= ' AND f.fk_soc = '.$socid; + } + + $sql .= ' ORDER BY '.$sortfield.' '.$sortorder; + $sql .= $db->plimit($limit + 1, $offset); + $resql = $db->query($sql); + + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + print_barre_liste($langs->trans('Payments'), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num); + print '
'; + print ''; + print_liste_field_titre('Invoice', $_SERVER["PHP_SELF"], 'f.ref', '', '', '', $sortfield, $sortorder); + print_liste_field_titre('Date', $_SERVER["PHP_SELF"], 'p.datep', '', '', '', $sortfield, $sortorder); + print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'c.libelle', '', '', '', $sortfield, $sortorder); + print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], 'p.amount', '', '', '', $sortfield, $sortorder, 'right '); print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch '); - print "\n"; - - while ($i < min($num, $limit)) - { - $objp = $db->fetch_object($resql); - - print ''; - print '\n"; - print '\n"; - print '\n"; - print ''; - print ''; - print ''; - - $parameters = array(); - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook - - $i++; - } - print '
'.$objp->ref."'.dol_print_date($db->jdate($objp->dp))."'.$objp->paiement_type.' '.$objp->num_payment."'.price($objp->amount).' 
'; - } + print "\n"; + + while ($i < min($num, $limit)) + { + $objp = $db->fetch_object($resql); + + print ''; + print ''.$objp->ref."\n"; + print ''.dol_print_date($db->jdate($objp->dp))."\n"; + print ''.$objp->paiement_type.' '.$objp->num_paiement."\n"; + print ''.price($objp->amount).''; + print ' '; + print ''; + + $parameters = array(); + $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $objp, $action); // Note that $action and $object may have been modified by hook + + $i++; + } + print ''; + } } llxFooter(); --- /tmp/dsg/dolibarr/htdocs/compta/github_paiement_charge.php +++ /tmp/dsg/dolibarr/htdocs/compta/client_paiement_charge.php @@ -31,7 +31,7 @@ $langs->load("bills"); $chid = GETPOST("id", 'int'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $amounts = array(); // Security check @@ -41,8 +41,6 @@ $socid = $user->socid; } -$charge = new ChargeSociales($db); - /* * Actions @@ -65,20 +63,20 @@ { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors'); $error++; - $action = 'create'; + $action = 'create'; } if ($datepaye == '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); $error++; - $action = 'create'; - } - if (!empty($conf->banque->enabled) && !($_POST["accountid"] > 0)) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors'); - $error++; - $action = 'create'; - } + $action = 'create'; + } + if (!empty($conf->banque->enabled) && !($_POST["accountid"] > 0)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors'); + $error++; + $action = 'create'; + } if (!$error) { @@ -94,59 +92,61 @@ } } - if (count($amounts) <= 0) - { - $error++; - setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors'); - $action = 'create'; - } - - if (!$error) - { - $db->begin(); - - // Create a line of payments - $paiement = new PaymentSocialContribution($db); - $paiement->chid = $chid; - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Amount list - $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml'); - $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); - $paiement->note = GETPOST("note", 'restricthtml'); - $paiement->note_private = GETPOST("note", 'restricthtml'); - - if (!$error) - { - $paymentid = $paiement->create($user, (GETPOST('closepaidcontrib') == 'on' ? 1 : 0)); - if ($paymentid < 0) - { - $error++; - setEventMessages($paiement->error, null, 'errors'); - $action = 'create'; - } - } - - if (!$error) - { - $result = $paiement->addPaymentToBank($user, 'payment_sc', '(SocialContributionPayment)', GETPOST('accountid', 'int'), '', ''); - if (!($result > 0)) - { - $error++; - setEventMessages($paiement->error, null, 'errors'); - $action = 'create'; - } - } - - if (!$error) - { - $db->commit(); - $loc = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid; - header('Location: '.$loc); - exit; - } else { - $db->rollback(); - } - } + if (count($amounts) <= 0) + { + $error++; + setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors'); + $action = 'create'; + } + + if (!$error) + { + $db->begin(); + + // Create a line of payments + $paiement = new PaymentSocialContribution($db); + $paiement->chid = $chid; + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Tableau de montant + $paiement->paiementtype = GETPOST("paiementtype", 'alphanohtml'); + $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); + $paiement->note = GETPOST("note", 'none'); + $paiement->note_private = GETPOST("note", 'none'); + + if (!$error) + { + $paymentid = $paiement->create($user, (GETPOST('closepaidcontrib') == 'on' ? 1 : 0)); + if ($paymentid < 0) + { + $error++; + setEventMessages($paiement->error, null, 'errors'); + $action = 'create'; + } + } + + if (!$error) + { + $result = $paiement->addPaymentToBank($user, 'payment_sc', '(SocialContributionPayment)', GETPOST('accountid', 'int'), '', ''); + if (!($result > 0)) + { + $error++; + setEventMessages($paiement->error, null, 'errors'); + $action = 'create'; + } + } + + if (!$error) + { + $db->commit(); + $loc = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$chid; + header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); + } + } } } @@ -160,12 +160,13 @@ $form = new Form($db); -// Form of charge payment creation +// Formulaire de creation d'un paiement de charge if ($action == 'create') { + $charge = new ChargeSociales($db); $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; + $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)) @@ -197,7 +198,7 @@ print ''; print ''; - print dol_get_fiche_head('', ''); + dol_fiche_head('', ''); print ''; @@ -222,21 +223,21 @@ print '';*/ print '"; print ''; print '\n"; print ''; print ''; print ''; print ''; // Number @@ -252,10 +253,10 @@ print '
'.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Date").''; - $datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int')); - $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (GETPOSTISSET("remonth") ? $datepaye : -1) : ''; - print $form->selectDate($datepayment, '', '', '', 0, "add_payment", 1, 1, 0, '', '', $charge->date_ech, '', 1, $langs->trans("DateOfSocialContribution")); + $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (empty($_POST["remonth"]) ?-1 : $datepaye) : 0; + print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1); print "
'.$langs->trans("PaymentMode").''; - $form->select_types_paiements(GETPOSTISSET("paiementtype") ? GETPOST("paiementtype") : $charge->paiementtype, "paiementtype"); + $form->select_types_paiements(isset($_POST["paiementtype"]) ? $_POST["paiementtype"] : $charge->paiementtype, "paiementtype"); print "
'.$langs->trans('AccountToDebit').''; - $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", 'int') : $charge->accountid, "accountid", 0, '', 2); // Show opend bank account list + $form->select_comptes(isset($_POST["accountid"]) ? $_POST["accountid"] : $charge->accountid, "accountid", 0, '', 1); // Show opend bank account list print '
'; - print dol_get_fiche_end(); + dol_fiche_end(); /* - * Other unpaid charges + * Autres charges impayees */ $num = 1; $i = 0; @@ -282,7 +283,9 @@ if ($objp->date_ech > 0) { print ''.dol_print_date($objp->date_ech, 'day').''."\n"; - } else { + } + else + { print "!!!\n"; } @@ -302,7 +305,9 @@ $remaintopay = $objp->amount - $sumpaid; print ''; print ''; - } else { + } + else + { print '-'; } print ""; @@ -327,11 +332,11 @@ print ""; - // Save payment button + // Bouton Save payment print '
'.$langs->trans("ClosePaidContributionsAutomatically"); print '
'; print '     '; - print ''; + print ''; print '
'; print "\n"; --- /tmp/dsg/dolibarr/htdocs/compta/github_recap-compta.php +++ /tmp/dsg/dolibarr/htdocs/compta/client_recap-compta.php @@ -46,8 +46,8 @@ // Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$sortfield = GETPOST('sortfield', 'alpha'); +$sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; @@ -58,8 +58,8 @@ $arrayfields = array( - 'f.datef'=>array('label'=>"Date", 'checked'=>1), - //... + 'f.datef'=>array('label'=>"Date", 'checked'=>1), + //... ); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -90,14 +90,14 @@ if ($id > 0) { - $param = ''; - if ($id > 0) $param .= '&socid='.$id; - - $head = societe_prepare_head($object); - - print dol_get_fiche_head($head, 'customer', $langs->trans("ThirdParty"), 0, 'company'); + $param = ''; + if ($id > 0) $param .= '&socid='.$id; + + $head = societe_prepare_head($object); + + dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), 0, 'company'); dol_banner_tab($object, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom', '', '', 0, '', '', 1); - print dol_get_fiche_end(); + dol_fiche_end(); if (!empty($conf->facture->enabled) && $user->rights->facture->lire) { @@ -106,7 +106,7 @@ print ''; print ''; - if (!empty($arrayfields['f.datef']['checked'])) print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER["PHP_SELF"], "f.datef", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); + if (!empty($arrayfields['f.datef']['checked'])) print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER["PHP_SELF"], "f.datef", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); print ''; print ''; print ''; @@ -211,11 +211,15 @@ } $db->free($resqlp); - } else { + } + else + { dol_print_error($db); } } - } else { + } + else + { dol_print_error($db); } @@ -284,7 +288,9 @@ print "
'.$langs->trans("Element").''.$langs->trans("Status").''.$langs->trans("Debit").'
"; } -} else { +} +else +{ dol_print_error($db); }