| Conditions | 135 |
| Total Lines | 796 |
| Code Lines | 542 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 1412 | public function list() |
||
| 1413 | { |
||
| 1414 | global $conf; |
||
| 1415 | global $db; |
||
| 1416 | global $user; |
||
| 1417 | global $hookmanager; |
||
| 1418 | global $user; |
||
| 1419 | global $menumanager; |
||
| 1420 | global $langs; |
||
| 1421 | |||
| 1422 | // Load translation files required by the page |
||
| 1423 | $langs->loadLangs(array("bills", "companies", "compta", "accountancy", "other", "productbatch", "products")); |
||
| 1424 | |||
| 1425 | $action = GETPOST('action', 'aZ09'); |
||
| 1426 | $massaction = GETPOST('massaction', 'alpha'); |
||
| 1427 | $confirm = GETPOST('confirm', 'alpha'); |
||
| 1428 | $toselect = GETPOST('toselect', 'array'); |
||
| 1429 | $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'accountancysupplierlist'; // To manage different context of search |
||
| 1430 | $optioncss = GETPOST('optioncss', 'alpha'); |
||
| 1431 | |||
| 1432 | $default_account = GETPOSTINT('default_account'); |
||
| 1433 | |||
| 1434 | // Select Box |
||
| 1435 | $mesCasesCochees = GETPOST('toselect', 'array'); |
||
| 1436 | |||
| 1437 | // Search Getpost |
||
| 1438 | $search_societe = GETPOST('search_societe', 'alpha'); |
||
| 1439 | $search_lineid = GETPOSTINT('search_lineid'); |
||
| 1440 | $search_ref = GETPOST('search_ref', 'alpha'); |
||
| 1441 | $search_ref_supplier = GETPOST('search_ref_supplier', 'alpha'); |
||
| 1442 | $search_invoice = GETPOST('search_invoice', 'alpha'); |
||
| 1443 | $search_label = GETPOST('search_label', 'alpha'); |
||
| 1444 | $search_desc = GETPOST('search_desc', 'alpha'); |
||
| 1445 | $search_amount = GETPOST('search_amount', 'alpha'); |
||
| 1446 | $search_account = GETPOST('search_account', 'alpha'); |
||
| 1447 | $search_vat = GETPOST('search_vat', 'alpha'); |
||
| 1448 | $search_date_startday = GETPOSTINT('search_date_startday'); |
||
| 1449 | $search_date_startmonth = GETPOSTINT('search_date_startmonth'); |
||
| 1450 | $search_date_startyear = GETPOSTINT('search_date_startyear'); |
||
| 1451 | $search_date_endday = GETPOSTINT('search_date_endday'); |
||
| 1452 | $search_date_endmonth = GETPOSTINT('search_date_endmonth'); |
||
| 1453 | $search_date_endyear = GETPOSTINT('search_date_endyear'); |
||
| 1454 | $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver |
||
| 1455 | $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear); |
||
| 1456 | $search_country = GETPOST('search_country', 'alpha'); |
||
| 1457 | $search_tvaintra = GETPOST('search_tvaintra', 'alpha'); |
||
| 1458 | |||
| 1459 | // Load variable for pagination |
||
| 1460 | $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : getDolGlobalString('ACCOUNTING_LIMIT_LIST_VENTILATION', $conf->liste_limit); |
||
| 1461 | $sortfield = GETPOST('sortfield', 'aZ09comma'); |
||
| 1462 | $sortorder = GETPOST('sortorder', 'aZ09comma'); |
||
| 1463 | $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); |
||
| 1464 | if (empty($page) || $page < 0) { |
||
| 1465 | $page = 0; |
||
| 1466 | } |
||
| 1467 | $offset = $limit * $page; |
||
| 1468 | $pageprev = $page - 1; |
||
| 1469 | $pagenext = $page + 1; |
||
| 1470 | if (!$sortfield) { |
||
| 1471 | $sortfield = "f.datef, f.ref, l.rowid"; |
||
| 1472 | } |
||
| 1473 | if (!$sortorder) { |
||
| 1474 | if (getDolGlobalInt('ACCOUNTING_LIST_SORT_VENTILATION_TODO') > 0) { |
||
| 1475 | $sortorder = "DESC"; |
||
| 1476 | } else { |
||
| 1477 | $sortorder = "ASC"; |
||
| 1478 | } |
||
| 1479 | } |
||
| 1480 | |||
| 1481 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
| 1482 | $hookmanager->initHooks(array('accountancysupplierlist')); |
||
| 1483 | |||
| 1484 | $formaccounting = new FormAccounting($db); |
||
| 1485 | $accountingAccount = new AccountingAccount($db); |
||
| 1486 | |||
| 1487 | $chartaccountcode = dol_getIdFromCode($db, getDolGlobalInt('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version'); |
||
| 1488 | |||
| 1489 | // Security check |
||
| 1490 | if (!isModEnabled('accounting')) { |
||
| 1491 | accessforbidden(); |
||
| 1492 | } |
||
| 1493 | if ($user->socid > 0) { |
||
| 1494 | accessforbidden(); |
||
| 1495 | } |
||
| 1496 | if (!$user->hasRight('accounting', 'mouvements', 'lire')) { |
||
| 1497 | accessforbidden(); |
||
| 1498 | } |
||
| 1499 | |||
| 1500 | // Define begin binding date |
||
| 1501 | if (empty($search_date_start) && getDolGlobalString('ACCOUNTING_DATE_START_BINDING')) { |
||
| 1502 | $search_date_start = $db->idate(getDolGlobalString('ACCOUNTING_DATE_START_BINDING')); |
||
| 1503 | } |
||
| 1504 | |||
| 1505 | |||
| 1506 | /* |
||
| 1507 | * Actions |
||
| 1508 | */ |
||
| 1509 | |||
| 1510 | if (GETPOST('cancel', 'alpha')) { |
||
| 1511 | $action = 'list'; |
||
| 1512 | $massaction = ''; |
||
| 1513 | } |
||
| 1514 | if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { |
||
| 1515 | $massaction = ''; |
||
| 1516 | } |
||
| 1517 | |||
| 1518 | $parameters = array(); |
||
| 1519 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 1520 | if ($reshook < 0) { |
||
| 1521 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
| 1522 | } |
||
| 1523 | |||
| 1524 | if (empty($reshook)) { |
||
| 1525 | // Purge search criteria |
||
| 1526 | if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers |
||
| 1527 | $search_societe = ''; |
||
| 1528 | $search_lineid = ''; |
||
| 1529 | $search_ref = ''; |
||
| 1530 | $search_ref_supplier = ''; |
||
| 1531 | $search_invoice = ''; |
||
| 1532 | $search_label = ''; |
||
| 1533 | $search_desc = ''; |
||
| 1534 | $search_amount = ''; |
||
| 1535 | $search_account = ''; |
||
| 1536 | $search_vat = ''; |
||
| 1537 | $search_date_startday = ''; |
||
| 1538 | $search_date_startmonth = ''; |
||
| 1539 | $search_date_startyear = ''; |
||
| 1540 | $search_date_endday = ''; |
||
| 1541 | $search_date_endmonth = ''; |
||
| 1542 | $search_date_endyear = ''; |
||
| 1543 | $search_date_start = ''; |
||
| 1544 | $search_date_end = ''; |
||
| 1545 | $search_country = ''; |
||
| 1546 | $search_tvaintra = ''; |
||
| 1547 | } |
||
| 1548 | |||
| 1549 | // Mass actions |
||
| 1550 | $objectclass = 'AccountingAccount'; |
||
| 1551 | $permissiontoread = $user->hasRight('accounting', 'read'); |
||
| 1552 | $permissiontodelete = $user->hasRight('accounting', 'delete'); |
||
| 1553 | $uploaddir = $conf->accounting->dir_output; |
||
| 1554 | include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php'; |
||
| 1555 | } |
||
| 1556 | |||
| 1557 | |||
| 1558 | if ($massaction == 'ventil' && $user->hasRight('accounting', 'bind', 'write')) { |
||
| 1559 | $msg = ''; |
||
| 1560 | |||
| 1561 | if (!empty($mesCasesCochees)) { |
||
| 1562 | $msg = '<div>' . $langs->trans("SelectedLines") . ': ' . count($mesCasesCochees) . '</div>'; |
||
| 1563 | $msg .= '<div class="detail">'; |
||
| 1564 | $cpt = 0; |
||
| 1565 | $ok = 0; |
||
| 1566 | $ko = 0; |
||
| 1567 | |||
| 1568 | foreach ($mesCasesCochees as $maLigneCochee) { |
||
| 1569 | $maLigneCourante = explode("_", $maLigneCochee); |
||
| 1570 | $monId = $maLigneCourante[0]; |
||
| 1571 | $monCompte = GETPOST('codeventil' . $monId); |
||
| 1572 | |||
| 1573 | if ($monCompte <= 0) { |
||
| 1574 | $msg .= '<div><span class="error">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("NoAccountSelected") . '</span></div>'; |
||
| 1575 | $ko++; |
||
| 1576 | } else { |
||
| 1577 | $sql = " UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det"; |
||
| 1578 | $sql .= " SET fk_code_ventilation = " . ((int) $monCompte); |
||
| 1579 | $sql .= " WHERE rowid = " . ((int) $monId); |
||
| 1580 | |||
| 1581 | $accountventilated = new AccountingAccount($db); |
||
| 1582 | $accountventilated->fetch($monCompte, '', 1); |
||
| 1583 | |||
| 1584 | dol_syslog('accountancy/supplier/list.php', LOG_DEBUG); |
||
| 1585 | if ($db->query($sql)) { |
||
| 1586 | $msg .= '<div><span class="green">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '</span></div>'; |
||
| 1587 | $ok++; |
||
| 1588 | } else { |
||
| 1589 | $msg .= '<div><span class="error">' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("NotVentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '<br> <pre>' . $sql . '</pre></span></div>'; |
||
| 1590 | $ko++; |
||
| 1591 | } |
||
| 1592 | } |
||
| 1593 | |||
| 1594 | $cpt++; |
||
| 1595 | } |
||
| 1596 | $msg .= '</div>'; |
||
| 1597 | $msg .= '<div>' . $langs->trans("EndProcessing") . '</div>'; |
||
| 1598 | } |
||
| 1599 | } |
||
| 1600 | |||
| 1601 | if (GETPOST('sortfield') == 'f.datef, f.ref, l.rowid') { |
||
| 1602 | $value = (GETPOST('sortorder') == 'asc,asc,asc' ? 0 : 1); |
||
| 1603 | require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; |
||
| 1604 | $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_TODO", $value, 'yesno', 0, '', $conf->entity); |
||
| 1605 | } |
||
| 1606 | |||
| 1607 | |||
| 1608 | /* |
||
| 1609 | * View |
||
| 1610 | */ |
||
| 1611 | |||
| 1612 | $form = new Form($db); |
||
| 1613 | $formother = new FormOther($db); |
||
| 1614 | |||
| 1615 | $help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Liaisons_comptables'; |
||
| 1616 | |||
| 1617 | llxHeader('', $langs->trans("SuppliersVentilation"), $help_url); |
||
| 1618 | |||
| 1619 | if (empty($chartaccountcode)) { |
||
| 1620 | print $langs->trans("ErrorChartOfAccountSystemNotSelected"); |
||
| 1621 | // End of page |
||
| 1622 | llxFooter(); |
||
| 1623 | $db->close(); |
||
| 1624 | exit; |
||
| 1625 | } |
||
| 1626 | |||
| 1627 | // Supplier Invoice Lines |
||
| 1628 | $sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype, f.fk_facture_source,"; |
||
| 1629 | $sql .= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,"; |
||
| 1630 | $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tva_tx as tva_tx_prod,"; |
||
| 1631 | if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { |
||
| 1632 | $sql .= " ppe.accountancy_code_sell as code_sell, ppe.accountancy_code_sell_intra as code_sell_intra, ppe.accountancy_code_sell_export as code_sell_export,"; |
||
| 1633 | $sql .= " ppe.accountancy_code_buy as code_buy, ppe.accountancy_code_buy_intra as code_buy_intra, ppe.accountancy_code_buy_export as code_buy_export,"; |
||
| 1634 | } else { |
||
| 1635 | $sql .= " p.accountancy_code_sell as code_sell, p.accountancy_code_sell_intra as code_sell_intra, p.accountancy_code_sell_export as code_sell_export,"; |
||
| 1636 | $sql .= " p.accountancy_code_buy as code_buy, p.accountancy_code_buy_intra as code_buy_intra, p.accountancy_code_buy_export as code_buy_export,"; |
||
| 1637 | } |
||
| 1638 | $sql .= " p.tosell as status, p.tobuy as status_buy,"; |
||
| 1639 | $sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,"; |
||
| 1640 | $sql .= " co.code as country_code, co.label as country_label,"; |
||
| 1641 | $sql .= " s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur,"; |
||
| 1642 | if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { |
||
| 1643 | $sql .= " spe.accountancy_code_customer as code_compta_client,"; |
||
| 1644 | $sql .= " spe.accountancy_code_supplier as code_compta_fournisseur,"; |
||
| 1645 | $sql .= " spe.accountancy_code_buy as company_code_buy"; |
||
| 1646 | } else { |
||
| 1647 | $sql .= " s.code_compta as code_compta_client,"; |
||
| 1648 | $sql .= " s.code_compta_fournisseur,"; |
||
| 1649 | $sql .= " s.accountancy_code_buy as company_code_buy"; |
||
| 1650 | } |
||
| 1651 | $parameters = array(); |
||
| 1652 | $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook |
||
| 1653 | $sql .= $hookmanager->resPrint; |
||
| 1654 | $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f"; |
||
| 1655 | $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; |
||
| 1656 | if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { |
||
| 1657 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); |
||
| 1658 | } |
||
| 1659 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON co.rowid = s.fk_pays "; |
||
| 1660 | $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn_det as l ON f.rowid = l.fk_facture_fourn"; |
||
| 1661 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product"; |
||
| 1662 | if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) { |
||
| 1663 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); |
||
| 1664 | } |
||
| 1665 | $alias_societe_perentity = !getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED') ? "s" : "spe"; |
||
| 1666 | $alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe"; |
||
| 1667 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON " . $alias_product_perentity . ".accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '" . $db->escape($chartaccountcode) . "' AND aa.entity = " . $conf->entity; |
||
| 1668 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa2 ON " . $alias_product_perentity . ".accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '" . $db->escape($chartaccountcode) . "' AND aa2.entity = " . $conf->entity; |
||
| 1669 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa3 ON " . $alias_product_perentity . ".accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '" . $db->escape($chartaccountcode) . "' AND aa3.entity = " . $conf->entity; |
||
| 1670 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa4 ON " . $alias_societe_perentity . ".accountancy_code_buy = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '" . $db->escape($chartaccountcode) . "' AND aa4.entity = " . $conf->entity; |
||
| 1671 | $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0"; |
||
| 1672 | $sql .= " AND l.product_type <= 2"; |
||
| 1673 | // Add search filter like |
||
| 1674 | if ($search_societe) { |
||
| 1675 | $sql .= natural_search('s.nom', $search_societe); |
||
| 1676 | } |
||
| 1677 | if ($search_lineid) { |
||
| 1678 | $sql .= natural_search("l.rowid", $search_lineid, 1); |
||
| 1679 | } |
||
| 1680 | if (strlen(trim($search_invoice))) { |
||
| 1681 | $sql .= natural_search(array("f.ref", "f.ref_supplier"), $search_invoice); |
||
| 1682 | } |
||
| 1683 | if (strlen(trim($search_ref))) { |
||
| 1684 | $sql .= natural_search("p.ref", $search_ref); |
||
| 1685 | } |
||
| 1686 | /*if (strlen(trim($search_ref_supplier))) { |
||
| 1687 | $sql .= natural_search("f.ref_supplier", $search_ref_supplier); |
||
| 1688 | }*/ |
||
| 1689 | if (strlen(trim($search_label))) { |
||
| 1690 | $sql .= natural_search(array("p.label", "f.libelle"), $search_label); |
||
| 1691 | } |
||
| 1692 | if (strlen(trim($search_desc))) { |
||
| 1693 | $sql .= natural_search("l.description", $search_desc); |
||
| 1694 | } |
||
| 1695 | if (strlen(trim($search_amount))) { |
||
| 1696 | $sql .= natural_search("l.total_ht", $search_amount, 1); |
||
| 1697 | } |
||
| 1698 | if (strlen(trim($search_account))) { |
||
| 1699 | $sql .= natural_search("aa.account_number", $search_account); |
||
| 1700 | } |
||
| 1701 | if (strlen(trim($search_vat))) { |
||
| 1702 | $sql .= natural_search("l.tva_tx", price2num($search_vat), 1); |
||
| 1703 | } |
||
| 1704 | if ($search_date_start) { |
||
| 1705 | $sql .= " AND f.datef >= '" . $db->idate($search_date_start) . "'"; |
||
| 1706 | } |
||
| 1707 | if ($search_date_end) { |
||
| 1708 | $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'"; |
||
| 1709 | } |
||
| 1710 | if (strlen(trim($search_country))) { |
||
| 1711 | $arrayofcode = getCountriesInEEC(); |
||
| 1712 | $country_code_in_EEC = $country_code_in_EEC_without_me = ''; |
||
| 1713 | foreach ($arrayofcode as $key => $value) { |
||
| 1714 | $country_code_in_EEC .= ($country_code_in_EEC ? "," : "") . "'" . $value . "'"; |
||
| 1715 | if ($value != $mysoc->country_code) { |
||
| 1716 | $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "") . "'" . $value . "'"; |
||
| 1717 | } |
||
| 1718 | } |
||
| 1719 | if ($search_country == 'special_allnotme') { |
||
| 1720 | $sql .= " AND co.code <> '" . $db->escape($mysoc->country_code) . "'"; |
||
| 1721 | } elseif ($search_country == 'special_eec') { |
||
| 1722 | $sql .= " AND co.code IN (" . $db->sanitize($country_code_in_EEC, 1) . ")"; |
||
| 1723 | } elseif ($search_country == 'special_eecnotme') { |
||
| 1724 | $sql .= " AND co.code IN (" . $db->sanitize($country_code_in_EEC_without_me, 1) . ")"; |
||
| 1725 | } elseif ($search_country == 'special_noteec') { |
||
| 1726 | $sql .= " AND co.code NOT IN (" . $db->sanitize($country_code_in_EEC, 1) . ")"; |
||
| 1727 | } else { |
||
| 1728 | $sql .= natural_search("co.code", $search_country); |
||
| 1729 | } |
||
| 1730 | } |
||
| 1731 | if (strlen(trim($search_tvaintra))) { |
||
| 1732 | $sql .= natural_search("s.tva_intra", $search_tvaintra); |
||
| 1733 | } |
||
| 1734 | if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) { |
||
| 1735 | $sql .= " AND f.type IN (" . FactureFournisseur::TYPE_STANDARD . "," . FactureFournisseur::TYPE_REPLACEMENT . "," . FactureFournisseur::TYPE_CREDIT_NOTE . "," . FactureFournisseur::TYPE_SITUATION . ")"; |
||
| 1736 | } else { |
||
| 1737 | $sql .= " AND f.type IN (" . FactureFournisseur::TYPE_STANDARD . "," . FactureFournisseur::TYPE_REPLACEMENT . "," . FactureFournisseur::TYPE_CREDIT_NOTE . "," . FactureFournisseur::TYPE_DEPOSIT . "," . FactureFournisseur::TYPE_SITUATION . ")"; |
||
| 1738 | } |
||
| 1739 | $sql .= " AND f.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy |
||
| 1740 | |||
| 1741 | // Add where from hooks |
||
| 1742 | $parameters = array(); |
||
| 1743 | $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook |
||
| 1744 | $sql .= $hookmanager->resPrint; |
||
| 1745 | |||
| 1746 | $sql .= $db->order($sortfield, $sortorder); |
||
| 1747 | |||
| 1748 | // Count total nb of records |
||
| 1749 | $nbtotalofrecords = ''; |
||
| 1750 | if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) { |
||
| 1751 | $result = $db->query($sql); |
||
| 1752 | $nbtotalofrecords = $db->num_rows($result); |
||
| 1753 | if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 |
||
| 1754 | $page = 0; |
||
| 1755 | $offset = 0; |
||
| 1756 | } |
||
| 1757 | } |
||
| 1758 | |||
| 1759 | $sql .= $db->plimit($limit + 1, $offset); |
||
| 1760 | |||
| 1761 | dol_syslog('accountancy/supplier/list.php', LOG_DEBUG); |
||
| 1762 | // MAX_JOIN_SIZE can be very low (ex: 300000) on some limited configurations (ex: https://www.online.net/fr/hosting/online-perso) |
||
| 1763 | // This big SELECT command may exceed the MAX_JOIN_SIZE limit => Therefore we use SQL_BIG_SELECTS=1 to disable the MAX_JOIN_SIZE security |
||
| 1764 | if ($db->type == 'mysqli') { |
||
| 1765 | $db->query("SET SQL_BIG_SELECTS=1"); |
||
| 1766 | } |
||
| 1767 | |||
| 1768 | $result = $db->query($sql); |
||
| 1769 | if ($result) { |
||
| 1770 | $num_lines = $db->num_rows($result); |
||
| 1771 | $i = 0; |
||
| 1772 | |||
| 1773 | $arrayofselected = is_array($toselect) ? $toselect : array(); |
||
| 1774 | |||
| 1775 | $param = ''; |
||
| 1776 | if (!empty($contextpage) && $contextpage != $_SERVER['PHP_SELF']) { |
||
| 1777 | $param .= '&contextpage=' . urlencode($contextpage); |
||
| 1778 | } |
||
| 1779 | if ($limit > 0 && $limit != $conf->liste_limit) { |
||
| 1780 | $param .= '&limit=' . ((int) $limit); |
||
| 1781 | } |
||
| 1782 | if ($search_societe) { |
||
| 1783 | $param .= '&search_societe=' . urlencode($search_societe); |
||
| 1784 | } |
||
| 1785 | if ($search_lineid) { |
||
| 1786 | $param .= '&search_lineid=' . urlencode((string) ($search_lineid)); |
||
| 1787 | } |
||
| 1788 | if ($search_date_startday) { |
||
| 1789 | $param .= '&search_date_startday=' . urlencode((string) ($search_date_startday)); |
||
| 1790 | } |
||
| 1791 | if ($search_date_startmonth) { |
||
| 1792 | $param .= '&search_date_startmonth=' . urlencode((string) ($search_date_startmonth)); |
||
| 1793 | } |
||
| 1794 | if ($search_date_startyear) { |
||
| 1795 | $param .= '&search_date_startyear=' . urlencode((string) ($search_date_startyear)); |
||
| 1796 | } |
||
| 1797 | if ($search_date_endday) { |
||
| 1798 | $param .= '&search_date_endday=' . urlencode((string) ($search_date_endday)); |
||
| 1799 | } |
||
| 1800 | if ($search_date_endmonth) { |
||
| 1801 | $param .= '&search_date_endmonth=' . urlencode((string) ($search_date_endmonth)); |
||
| 1802 | } |
||
| 1803 | if ($search_date_endyear) { |
||
| 1804 | $param .= '&search_date_endyear=' . urlencode((string) ($search_date_endyear)); |
||
| 1805 | } |
||
| 1806 | if ($search_invoice) { |
||
| 1807 | $param .= '&search_invoice=' . urlencode($search_invoice); |
||
| 1808 | } |
||
| 1809 | if ($search_ref) { |
||
| 1810 | $param .= '&search_ref=' . urlencode($search_ref); |
||
| 1811 | } |
||
| 1812 | if ($search_ref_supplier) { |
||
| 1813 | $param .= '&search_ref_supplier=' . urlencode($search_ref_supplier); |
||
| 1814 | } |
||
| 1815 | if ($search_label) { |
||
| 1816 | $param .= '&search_label=' . urlencode($search_label); |
||
| 1817 | } |
||
| 1818 | if ($search_desc) { |
||
| 1819 | $param .= '&search_desc=' . urlencode($search_desc); |
||
| 1820 | } |
||
| 1821 | if ($search_amount) { |
||
| 1822 | $param .= '&search_amount=' . urlencode($search_amount); |
||
| 1823 | } |
||
| 1824 | if ($search_vat) { |
||
| 1825 | $param .= '&search_vat=' . urlencode($search_vat); |
||
| 1826 | } |
||
| 1827 | if ($search_country) { |
||
| 1828 | $param .= "&search_country=" . urlencode($search_country); |
||
| 1829 | } |
||
| 1830 | if ($search_tvaintra) { |
||
| 1831 | $param .= "&search_tvaintra=" . urlencode($search_tvaintra); |
||
| 1832 | } |
||
| 1833 | |||
| 1834 | $arrayofmassactions = array( |
||
| 1835 | 'ventil' => img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans("Ventilate") |
||
| 1836 | ,'set_default_account' => img_picto('', 'check', 'class="pictofixedwidth"') . $langs->trans("ConfirmPreselectAccount") |
||
| 1837 | //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), |
||
| 1838 | //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), |
||
| 1839 | ); |
||
| 1840 | //if ($user->hasRight('mymodule', 'supprimer')) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); |
||
| 1841 | //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); |
||
| 1842 | if ($massaction !== 'set_default_account') { |
||
| 1843 | $massactionbutton = $form->selectMassAction('ventil', $arrayofmassactions, 1); |
||
| 1844 | } |
||
| 1845 | |||
| 1846 | print '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">' . "\n"; |
||
| 1847 | print '<input type="hidden" name="action" value="ventil">'; |
||
| 1848 | if ($optioncss != '') { |
||
| 1849 | print '<input type="hidden" name="optioncss" value="' . $optioncss . '">'; |
||
| 1850 | } |
||
| 1851 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
| 1852 | print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; |
||
| 1853 | print '<input type="hidden" name="sortfield" value="' . $sortfield . '">'; |
||
| 1854 | print '<input type="hidden" name="sortorder" value="' . $sortorder . '">'; |
||
| 1855 | print '<input type="hidden" name="page" value="' . $page . '">'; |
||
| 1856 | |||
| 1857 | // @phan-suppress-next-line PhanPluginSuspiciousParamOrder |
||
| 1858 | print_barre_liste($langs->trans("InvoiceLines"), $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit); |
||
| 1859 | |||
| 1860 | if ($massaction == 'set_default_account') { |
||
| 1861 | $formquestion = array(); |
||
| 1862 | $formquestion[] = array('type' => 'other', |
||
| 1863 | 'name' => 'set_default_account', |
||
| 1864 | 'label' => $langs->trans("AccountancyCode"), |
||
| 1865 | 'value' => $formaccounting->select_account('', 'default_account', 1, array(), 0, 0, 'maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone')); |
||
| 1866 | print $form->formconfirm($_SERVER['PHP_SELF'], $langs->trans("ConfirmPreselectAccount"), $langs->trans("ConfirmPreselectAccountQuestion", count($toselect)), "confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1); |
||
| 1867 | } |
||
| 1868 | |||
| 1869 | print '<span class="opacitymedium">' . $langs->trans("DescVentilTodoCustomer") . '</span></br><br>'; |
||
| 1870 | |||
| 1871 | if (!empty($msg)) { |
||
| 1872 | print $msg . '<br>'; |
||
| 1873 | } |
||
| 1874 | |||
| 1875 | $moreforfilter = ''; |
||
| 1876 | |||
| 1877 | print '<div class="div-table-responsive">'; |
||
| 1878 | print '<table class="tagtable liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n"; |
||
| 1879 | |||
| 1880 | // We add search filter |
||
| 1881 | print '<tr class="liste_titre_filter">'; |
||
| 1882 | print '<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '"></td>'; |
||
| 1883 | print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>'; |
||
| 1884 | //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'"></td>'; |
||
| 1885 | print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>'; |
||
| 1886 | print '<td class="liste_titre center">'; |
||
| 1887 | print '<div class="nowrapfordate">'; |
||
| 1888 | print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); |
||
| 1889 | print '</div>'; |
||
| 1890 | print '<div class="nowrapfordate">'; |
||
| 1891 | print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); |
||
| 1892 | print '</div>'; |
||
| 1893 | print '</td>'; |
||
| 1894 | print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>'; |
||
| 1895 | print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>'; |
||
| 1896 | print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>'; |
||
| 1897 | print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_vat" placeholder="%" size="1" value="' . dol_escape_htmltag($search_vat) . '"></td>'; |
||
| 1898 | print '<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="' . dol_escape_htmltag($search_societe) . '"></td>'; |
||
| 1899 | print '<td class="liste_titre">'; |
||
| 1900 | print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth100', 'code2', 1, 0, 1); |
||
| 1901 | //print '<input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '">'; |
||
| 1902 | print '</td>'; |
||
| 1903 | print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="' . dol_escape_htmltag($search_tvaintra) . '"></td>'; |
||
| 1904 | print '<td class="liste_titre"></td>'; |
||
| 1905 | print '<td class="liste_titre"></td>'; |
||
| 1906 | print '<td class="center liste_titre">'; |
||
| 1907 | $searchpicto = $form->showFilterButtons(); |
||
| 1908 | print $searchpicto; |
||
| 1909 | print '</td>'; |
||
| 1910 | print "</tr>\n"; |
||
| 1911 | |||
| 1912 | print '<tr class="liste_titre">'; |
||
| 1913 | print_liste_field_titre("LineId", $_SERVER['PHP_SELF'], "l.rowid", "", $param, '', $sortfield, $sortorder); |
||
| 1914 | print_liste_field_titre("Invoice", $_SERVER['PHP_SELF'], "f.ref", "", $param, '', $sortfield, $sortorder); |
||
| 1915 | //print_liste_field_titre("RefSupplier", $_SERVER['PHP_SELF'], "f.ref_supplier", "", $param, '', $sortfield, $sortorder); |
||
| 1916 | print_liste_field_titre("InvoiceLabel", $_SERVER['PHP_SELF'], "f.libelle", "", $param, '', $sortfield, $sortorder); |
||
| 1917 | print_liste_field_titre("Date", $_SERVER['PHP_SELF'], "f.datef, f.ref, l.rowid", "", $param, '', $sortfield, $sortorder, 'center '); |
||
| 1918 | print_liste_field_titre("ProductRef", $_SERVER['PHP_SELF'], "p.ref", "", $param, '', $sortfield, $sortorder); |
||
| 1919 | //print_liste_field_titre("ProductLabel", $_SERVER['PHP_SELF'], "p.label", "", $param, '', $sortfield, $sortorder); |
||
| 1920 | print_liste_field_titre("ProductDescription", $_SERVER['PHP_SELF'], "l.description", "", $param, '', $sortfield, $sortorder); |
||
| 1921 | print_liste_field_titre("Amount", $_SERVER['PHP_SELF'], "l.total_ht", "", $param, '', $sortfield, $sortorder, 'right maxwidth50 '); |
||
| 1922 | print_liste_field_titre("VATRate", $_SERVER['PHP_SELF'], "l.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ', '', 1); |
||
| 1923 | print_liste_field_titre("ThirdParty", $_SERVER['PHP_SELF'], "s.nom", "", $param, '', $sortfield, $sortorder); |
||
| 1924 | print_liste_field_titre("Country", $_SERVER['PHP_SELF'], "co.label", "", $param, '', $sortfield, $sortorder); |
||
| 1925 | print_liste_field_titre("VATIntraShort", $_SERVER['PHP_SELF'], "s.tva_intra", "", $param, '', $sortfield, $sortorder); |
||
| 1926 | print_liste_field_titre("DataUsedToSuggestAccount", '', '', '', '', '', '', '', 'nowraponall '); |
||
| 1927 | print_liste_field_titre("AccountAccountingSuggest", '', '', '', '', '', '', '', 'center '); |
||
| 1928 | $checkpicto = ''; |
||
| 1929 | if ($massactionbutton) { |
||
| 1930 | $checkpicto = $form->showCheckAddButtons('checkforselect', 1); |
||
| 1931 | } |
||
| 1932 | print_liste_field_titre($checkpicto, '', '', '', '', '', '', '', 'center '); |
||
| 1933 | print "</tr>\n"; |
||
| 1934 | |||
| 1935 | $thirdpartystatic = new Societe($db); |
||
| 1936 | $facturefourn_static = new FactureFournisseur($db); |
||
| 1937 | $facturefourn_static_det = new SupplierInvoiceLine($db); |
||
| 1938 | $product_static = new Product($db); |
||
| 1939 | |||
| 1940 | |||
| 1941 | $accountingaccount_codetotid_cache = array(); |
||
| 1942 | |||
| 1943 | while ($i < min($num_lines, $limit)) { |
||
| 1944 | $objp = $db->fetch_object($result); |
||
| 1945 | |||
| 1946 | // product_type: 0 = service, 1 = product |
||
| 1947 | // if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service |
||
| 1948 | // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB ! |
||
| 1949 | $code_buy_l = ''; |
||
| 1950 | $code_buy_p = ''; |
||
| 1951 | $code_buy_t = ''; |
||
| 1952 | |||
| 1953 | $thirdpartystatic->id = $objp->socid; |
||
| 1954 | $thirdpartystatic->name = $objp->name; |
||
| 1955 | $thirdpartystatic->client = $objp->client; |
||
| 1956 | $thirdpartystatic->fournisseur = $objp->fournisseur; |
||
| 1957 | $thirdpartystatic->code_client = $objp->code_client; |
||
| 1958 | $thirdpartystatic->code_compta_client = $objp->code_compta_client; |
||
| 1959 | $thirdpartystatic->code_fournisseur = $objp->code_fournisseur; |
||
| 1960 | $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur; |
||
| 1961 | $thirdpartystatic->email = $objp->email; |
||
| 1962 | $thirdpartystatic->country_code = $objp->country_code; |
||
| 1963 | $thirdpartystatic->tva_intra = $objp->tva_intra; |
||
| 1964 | $thirdpartystatic->code_compta_product = $objp->company_code_buy; // The accounting account for product stored on thirdparty object (for level3 suggestion) |
||
| 1965 | |||
| 1966 | $product_static->ref = $objp->product_ref; |
||
| 1967 | $product_static->id = $objp->product_id; |
||
| 1968 | $product_static->type = $objp->type; |
||
| 1969 | $product_static->label = $objp->product_label; |
||
| 1970 | $product_static->status = $objp->status; |
||
| 1971 | $product_static->status_buy = $objp->status_buy; |
||
| 1972 | $product_static->accountancy_code_sell = $objp->code_sell; |
||
| 1973 | $product_static->accountancy_code_sell_intra = $objp->code_sell_intra; |
||
| 1974 | $product_static->accountancy_code_sell_export = $objp->code_sell_export; |
||
| 1975 | $product_static->accountancy_code_buy = $objp->code_buy; |
||
| 1976 | $product_static->accountancy_code_buy_intra = $objp->code_buy_intra; |
||
| 1977 | $product_static->accountancy_code_buy_export = $objp->code_buy_export; |
||
| 1978 | $product_static->tva_tx = $objp->tva_tx_prod; |
||
| 1979 | |||
| 1980 | $facturefourn_static->ref = $objp->ref; |
||
| 1981 | $facturefourn_static->id = $objp->facid; |
||
| 1982 | $facturefourn_static->type = $objp->ftype; |
||
| 1983 | $facturefourn_static->ref_supplier = $objp->ref_supplier; |
||
| 1984 | $facturefourn_static->label = $objp->invoice_label; |
||
| 1985 | $facturefourn_static->date = $db->jdate($objp->datef); |
||
| 1986 | $facturefourn_static->fk_facture_source = $objp->fk_facture_source; |
||
| 1987 | |||
| 1988 | $facturefourn_static_det->id = $objp->rowid; |
||
| 1989 | $facturefourn_static_det->total_ht = $objp->total_ht; |
||
| 1990 | $facturefourn_static_det->tva_tx = $objp->tva_tx_line; |
||
| 1991 | $facturefourn_static_det->vat_src_code = $objp->vat_src_code; |
||
| 1992 | $facturefourn_static_det->product_type = $objp->type_l; |
||
| 1993 | $facturefourn_static_det->desc = $objp->description; |
||
| 1994 | |||
| 1995 | $accountingAccountArray = array( |
||
| 1996 | 'dom' => $objp->aarowid, |
||
| 1997 | 'intra' => $objp->aarowid_intra, |
||
| 1998 | 'export' => $objp->aarowid_export, |
||
| 1999 | 'thirdparty' => $objp->aarowid_thirdparty); |
||
| 2000 | |||
| 2001 | $code_buy_p_notset = ''; |
||
| 2002 | $code_buy_t_notset = ''; |
||
| 2003 | |||
| 2004 | $suggestedid = 0; |
||
| 2005 | |||
| 2006 | $return = $accountingAccount->getAccountingCodeToBind($mysoc, $thirdpartystatic, $product_static, $facturefourn_static, $facturefourn_static_det, $accountingAccountArray, 'supplier'); |
||
| 2007 | if (!is_array($return) && $return < 0) { |
||
| 2008 | setEventMessage($accountingAccount->error, 'errors'); |
||
| 2009 | } else { |
||
| 2010 | $suggestedid = $return['suggestedid']; |
||
| 2011 | $suggestedaccountingaccountfor = $return['suggestedaccountingaccountfor']; |
||
| 2012 | $suggestedaccountingaccountbydefaultfor = $return['suggestedaccountingaccountbydefaultfor']; |
||
| 2013 | $code_buy_l = $return['code_l']; |
||
| 2014 | $code_buy_p = $return['code_p']; |
||
| 2015 | $code_buy_t = $return['code_t']; |
||
| 2016 | } |
||
| 2017 | //var_dump($return); |
||
| 2018 | |||
| 2019 | if (!empty($code_buy_p)) { |
||
| 2020 | // Value was defined previously |
||
| 2021 | } else { |
||
| 2022 | $code_buy_p_notset = 'color:orange'; |
||
| 2023 | } |
||
| 2024 | if (empty($code_buy_l) && empty($code_buy_p)) { |
||
| 2025 | $code_buy_p_notset = 'color:red'; |
||
| 2026 | } |
||
| 2027 | /*if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber' && empty($code_sell_p_notset)) { |
||
| 2028 | $code_sell_p_notset = 'color:orange'; |
||
| 2029 | }*/ |
||
| 2030 | |||
| 2031 | // $code_buy_l is now default code of product/service |
||
| 2032 | // $code_buy_p is now code of product/service |
||
| 2033 | // $code_buy_t is now code of thirdparty |
||
| 2034 | //var_dump($code_buy_l.' - '.$code_buy_p.' - '.$code_buy_t.' -> '.$suggestedid.' ('.$suggestedaccountingaccountbydefaultfor.' '.$suggestedaccountingaccountfor.')'); |
||
| 2035 | |||
| 2036 | print '<tr class="oddeven">'; |
||
| 2037 | |||
| 2038 | // Line id |
||
| 2039 | print '<td>' . $facturefourn_static_det->id . '</td>'; |
||
| 2040 | |||
| 2041 | // Ref Invoice |
||
| 2042 | print '<td class="nowraponall">' . $facturefourn_static->getNomUrl(1); |
||
| 2043 | if ($objp->ref_supplier) { |
||
| 2044 | print '<br><span class="opacitymedium small">' . dol_escape_htmltag($objp->ref_supplier) . '</span>'; |
||
| 2045 | } |
||
| 2046 | print '</td>'; |
||
| 2047 | |||
| 2048 | // Ref supplier invoice |
||
| 2049 | /*print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($objp->ref_supplier).'">'; |
||
| 2050 | print $objp->ref_supplier; |
||
| 2051 | print '</td>';*/ |
||
| 2052 | |||
| 2053 | // Supplier invoice label |
||
| 2054 | print '<td class="tdoverflowmax100 small" title="' . dol_escape_htmltag($objp->invoice_label) . '">'; |
||
| 2055 | print dol_escape_htmltag($objp->invoice_label); |
||
| 2056 | print '</td>'; |
||
| 2057 | |||
| 2058 | // Date |
||
| 2059 | print '<td class="center">' . dol_print_date($facturefourn_static->date, 'day') . '</td>'; |
||
| 2060 | |||
| 2061 | // Ref Product |
||
| 2062 | print '<td class="tdoverflowmax100">'; |
||
| 2063 | if ($product_static->id > 0) { |
||
| 2064 | print $product_static->getNomUrl(1); |
||
| 2065 | } |
||
| 2066 | if ($product_static->label) { |
||
| 2067 | print '<br><span class="opacitymedium small">' . dol_escape_htmltag($product_static->label) . '</span>'; |
||
| 2068 | } |
||
| 2069 | print '</td>'; |
||
| 2070 | |||
| 2071 | // Description of line |
||
| 2072 | print '<td class="tdoverflowonsmartphone small">'; |
||
| 2073 | $text = dolGetFirstLineOfText(dol_string_nohtmltag($facturefourn_static_det->desc, 1)); |
||
| 2074 | $trunclength = getDolGlobalInt('ACCOUNTING_LENGTH_DESCRIPTION', 32); |
||
| 2075 | print $form->textwithtooltip(dol_trunc($text, $trunclength), $facturefourn_static_det->desc); |
||
| 2076 | print '</td>'; |
||
| 2077 | |||
| 2078 | print '<td class="right nowraponall amount">'; |
||
| 2079 | print price($objp->total_ht); |
||
| 2080 | print '</td>'; |
||
| 2081 | |||
| 2082 | // Vat rate |
||
| 2083 | $code_vat_differ = ''; |
||
| 2084 | //if ($objp->vat_tx_l != $objp->vat_tx_p && price2num($objp->vat_tx_p) && price2num($objp->vat_tx_l)) { // Note: having a vat rate of 0 is often the normal case when sells is intra b2b or to export |
||
| 2085 | // $code_vat_differ = 'warning bold'; |
||
| 2086 | //} |
||
| 2087 | print '<td class="right' . ($code_vat_differ ? ' ' . $code_vat_differ : '') . '">'; |
||
| 2088 | print vatrate($facturefourn_static_det->tva_tx . ($facturefourn_static_det->vat_src_code ? ' (' . $facturefourn_static_det->vat_src_code . ')' : ''), false, 0, 0, 1); |
||
| 2089 | print '</td>'; |
||
| 2090 | |||
| 2091 | // Thirdparty |
||
| 2092 | print '<td class="tdoverflowmax100">' . $thirdpartystatic->getNomUrl(1, 'supplier') . '</td>'; |
||
| 2093 | |||
| 2094 | // Country |
||
| 2095 | $labelcountry = ($objp->country_code && ($langs->trans("Country" . $objp->country_code) != "Country" . $objp->country_code)) ? $langs->trans("Country" . $objp->country_code) : $objp->country_label; |
||
| 2096 | print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($labelcountry) . '">'; |
||
| 2097 | print dol_escape_htmltag($labelcountry); |
||
| 2098 | print '</td>'; |
||
| 2099 | |||
| 2100 | // VAT Num |
||
| 2101 | print '<td class="tdoverflowmax80" title="' . dol_escape_htmltag($objp->tva_intra) . '">' . dol_escape_htmltag($objp->tva_intra) . '</td>'; |
||
| 2102 | |||
| 2103 | // Found accounts |
||
| 2104 | print '<td class="small">'; |
||
| 2105 | $s = '1. ' . (($facturefourn_static_det->product_type == 1) ? $langs->trans("DefaultForService") : $langs->trans("DefaultForProduct")) . ': '; |
||
| 2106 | $shelp = ''; |
||
| 2107 | $ttype = 'help'; |
||
| 2108 | if ($suggestedaccountingaccountbydefaultfor == 'eec') { |
||
| 2109 | $shelp .= $langs->trans("SaleEEC"); |
||
| 2110 | } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithvat') { |
||
| 2111 | $shelp = $langs->trans("SaleEECWithVAT"); |
||
| 2112 | } elseif ($suggestedaccountingaccountbydefaultfor == 'eecwithoutvatnumber') { |
||
| 2113 | $shelp = $langs->trans("SaleEECWithoutVATNumber"); |
||
| 2114 | $ttype = 'warning'; |
||
| 2115 | } elseif ($suggestedaccountingaccountbydefaultfor == 'export') { |
||
| 2116 | $shelp .= $langs->trans("SaleExport"); |
||
| 2117 | } |
||
| 2118 | $s .= ($code_buy_l > 0 ? length_accountg($code_buy_l) : '<span style="' . $code_buy_p_notset . '">' . $langs->trans("NotDefined") . '</span>'); |
||
| 2119 | print $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1); |
||
| 2120 | if ($product_static->id > 0) { |
||
| 2121 | print '<br>'; |
||
| 2122 | $s = '2. ' . (($facturefourn_static_det->product_type == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")) . ': '; |
||
| 2123 | $shelp = ''; |
||
| 2124 | $ttype = 'help'; |
||
| 2125 | if ($suggestedaccountingaccountfor == 'eec') { |
||
| 2126 | $shelp = $langs->trans("SaleEEC"); |
||
| 2127 | } elseif ($suggestedaccountingaccountfor == 'eecwithvat') { |
||
| 2128 | $shelp = $langs->trans("SaleEECWithVAT"); |
||
| 2129 | } elseif ($suggestedaccountingaccountfor == 'eecwithoutvatnumber') { |
||
| 2130 | $shelp = $langs->trans("SaleEECWithoutVATNumber"); |
||
| 2131 | $ttype = 'warning'; |
||
| 2132 | } elseif ($suggestedaccountingaccountfor == 'export') { |
||
| 2133 | $shelp = $langs->trans("SaleExport"); |
||
| 2134 | } |
||
| 2135 | $s .= (empty($code_buy_p) ? '<span style="' . $code_buy_p_notset . '">' . $langs->trans("NotDefined") . '</span>' : length_accountg($code_buy_p)); |
||
| 2136 | print $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1); |
||
| 2137 | } else { |
||
| 2138 | print '<br>'; |
||
| 2139 | $s = '2. ' . (($objp->type_l == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")) . ': '; |
||
| 2140 | $shelp = ''; |
||
| 2141 | $s .= $langs->trans("NotDefined"); |
||
| 2142 | print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1); |
||
| 2143 | } |
||
| 2144 | if (getDolGlobalString('ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY')) { |
||
| 2145 | print '<br>'; |
||
| 2146 | $s = '3. ' . (($facturefourn_static_det->product_type == 1) ? $langs->trans("ServiceForThisThirdparty") : $langs->trans("ProductForThisThirdparty")) . ': '; |
||
| 2147 | $shelp = ''; |
||
| 2148 | $s .= ($code_buy_t > 0 ? length_accountg($code_buy_t) : '<span style="' . $code_buy_t_notset . '">' . $langs->trans("NotDefined") . '</span>'); |
||
| 2149 | print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1); |
||
| 2150 | } |
||
| 2151 | print '</td>'; |
||
| 2152 | |||
| 2153 | // Suggested accounting account |
||
| 2154 | print '<td>'; |
||
| 2155 | print $formaccounting->select_account(($default_account > 0 && $confirm === 'yes' && in_array($objp->rowid . "_" . $i, $toselect)) ? $default_account : $suggestedid, 'codeventil' . $facturefourn_static_det->id, 1, array(), 0, 0, 'codeventil maxwidth150 maxwidthonsmartphone', 'cachewithshowemptyone'); |
||
| 2156 | print '</td>'; |
||
| 2157 | |||
| 2158 | // Column with checkbox |
||
| 2159 | print '<td class="center">'; |
||
| 2160 | $ischecked = 0; |
||
| 2161 | if (!empty($suggestedid) && $suggestedaccountingaccountfor != '' && $suggestedaccountingaccountfor != 'eecwithoutvatnumber') { |
||
| 2162 | $ischecked = 1; |
||
| 2163 | } |
||
| 2164 | |||
| 2165 | if (!empty($toselect)) { |
||
| 2166 | $ischecked = 0; |
||
| 2167 | if (in_array($objp->rowid . "_" . $i, $toselect)) { |
||
| 2168 | $ischecked = 1; |
||
| 2169 | } |
||
| 2170 | } |
||
| 2171 | |||
| 2172 | print '<input type="checkbox" class="flat checkforselect checkforselect' . $facturefourn_static_det->id . '" name="toselect[]" value="' . $facturefourn_static_det->id . "_" . $i . '"' . ($ischecked ? " checked" : "") . '/>'; |
||
| 2173 | print '</td>'; |
||
| 2174 | |||
| 2175 | print '</tr>'; |
||
| 2176 | $i++; |
||
| 2177 | } |
||
| 2178 | if ($num_lines == 0) { |
||
| 2179 | print '<tr><td colspan="14"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>'; |
||
| 2180 | } |
||
| 2181 | |||
| 2182 | print '</table>'; |
||
| 2183 | print "</div>"; |
||
| 2184 | |||
| 2185 | print '</form>'; |
||
| 2186 | } else { |
||
| 2187 | print $db->error(); |
||
| 2188 | } |
||
| 2189 | if ($db->type == 'mysqli') { |
||
| 2190 | $db->query("SET SQL_BIG_SELECTS=0"); // Enable MAX_JOIN_SIZE limitation |
||
| 2191 | } |
||
| 2192 | |||
| 2193 | // Add code to auto check the box when we select an account |
||
| 2194 | print '<script type="text/javascript"> |
||
| 2195 | jQuery(document).ready(function() { |
||
| 2196 | jQuery(".codeventil").change(function() { |
||
| 2197 | var s=$(this).attr("id").replace("codeventil", "") |
||
| 2198 | console.log(s+" "+$(this).val()); |
||
| 2199 | if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false); |
||
| 2200 | else jQuery(".checkforselect"+s).prop("checked", true); |
||
| 2201 | }); |
||
| 2202 | }); |
||
| 2203 | </script>'; |
||
| 2204 | |||
| 2205 | // End of page |
||
| 2206 | llxFooter(); |
||
| 2207 | $db->close(); |
||
| 2208 | } |
||
| 2210 |