This commit is contained in:
Maxime Kohlhaas 2017-07-17 11:38:37 +02:00
commit 843172ccc8
7 changed files with 79 additions and 56 deletions

View File

@ -83,9 +83,9 @@ if ($user->societe_id > 0 && empty($id_bank_account))
/*
* Actions
*/
$error = 0;
$year_current = strftime("%Y", dol_now());
$pastmonth = strftime("%m", dol_now()) - 1;
$pastmonthyear = $year_current;
@ -163,15 +163,16 @@ if ($result) {
// one line for bank jounral = tabbq
// one line for thirdparty journal = tabtp
$i = 0;
while ( $i < $num )
while ( $i < $num )
{
$obj = $db->fetch_object($result);
// Set accountancy code (for bank and thirdparty)
$compta_bank = $obj->account_number;
if ($obj->label == '(SupplierInvoicePayment)')
$compta_soc = 'NotDefined';
if ($obj->label == '(SupplierInvoicePayment)' || $obj->label == '(SupplierInvoicePaymentBack)')
$compta_soc = (! empty($obj->code_compta_fournisseur) ? $obj->code_compta_fournisseur : $account_supplier);
if ($obj->label == '(CustomerInvoicePayment)')
if ($obj->label == '(CustomerInvoicePayment)' || $obj->label == '(CustomerInvoicePaymentBack)')
$compta_soc = (! empty($obj->code_compta) ? $obj->code_compta : $account_customer);
$tabcompany[$obj->rowid] = array (
@ -179,7 +180,7 @@ if ($result) {
'name' => $obj->name,
'code_compta' => $compta_soc,
);
$compta_user = (! empty($obj->accountancy_code) ? $obj->accountancy_code : $account_employee);
$tabuser[$obj->rowid] = array (
@ -205,10 +206,10 @@ if ($result) {
if (is_array($links)) {
// Now loop on each link of record in bank.
foreach ( $links as $key => $val ) {
if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport'))) // So we excluded 'company' here
{
// We save tabtype for a future use, to remember what kind of payment it is
// We save tabtype for a future use, to remember what kind of payment it is
$tabtype[$obj->rowid] = $links[$key]['type'];
}
@ -225,12 +226,12 @@ if ($result) {
$societestatic->id = $links[$key]['url_id'];
$societestatic->name = $links[$key]['label'];
$tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
if ($compta_soc) $tabtp[$obj->rowid][$compta_soc] += $obj->amount;
} else if ($links[$key]['type'] == 'user') {
$userstatic->id = $links[$key]['url_id'];
$userstatic->name = $links[$key]['label'];
$tabpay[$obj->rowid]["soclib"] = $userstatic->getNomUrl(1, '', 30);
$tabtp[$obj->rowid][$compta_user] += $obj->amount;
if ($compta_user) $tabtp[$obj->rowid][$compta_user] += $obj->amount;
} else if ($links[$key]['type'] == 'sc') {
$chargestatic->id = $links[$key]['url_id'];
$chargestatic->ref = $links[$key]['url_id'];
@ -290,7 +291,7 @@ if ($result) {
$tabbq[$obj->rowid][$compta_bank] += $obj->amount;
// Check account number is ok
/*if ($action == 'writebookkeeping') // Make test now in such a case
{
@ -309,7 +310,7 @@ if ($result) {
setEventMessages($langs->trans('ErrorAccountancyCodeOnThirdPartyNotDefined'), null, 'errors');
}
}*/
// if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
$i ++;
@ -330,16 +331,16 @@ if (! $error && $action == 'writebookkeeping') {
$error = 0;
foreach ( $tabpay as $key => $val ) { // $key is rowid into llx_bank
$errorforline = 0;
$db->begin();
// Bank
if (! $errorforline)
{
// Line into bank account
foreach ( $tabbq[$key] as $k => $mt )
foreach ( $tabbq[$key] as $k => $mt )
{
if ($mt) {
$bookkeeping = new BookKeeping($db);
@ -357,10 +358,10 @@ if (! $error && $action == 'writebookkeeping') {
$bookkeeping->code_journal = $journal;
$bookkeeping->fk_user_author = $user->id;
$bookkeeping->date_create = $now;
if ($tabtype[$key] == 'payment') {
$bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
$sqlmid = 'SELECT fac.facnumber';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid";
@ -374,7 +375,7 @@ if (! $error && $action == 'writebookkeeping') {
}
} else if ($tabtype[$key] == 'payment_supplier') {
$bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
$sqlmid = 'SELECT facf.ref_supplier, facf.ref';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
@ -388,7 +389,7 @@ if (! $error && $action == 'writebookkeeping') {
}
} else if ($tabtype[$key] == 'payment_expensereport') {
$bookkeeping->code_tiers = $tabuser[$key]['accountancy_code'];
$sqlmid = 'SELECT e.ref';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "expensereport as e";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_expensereport as payer ON payer.fk_expensereport=e.rowid";
@ -400,7 +401,7 @@ if (! $error && $action == 'writebookkeeping') {
$bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport
}
}
$result = $bookkeeping->create($user);
if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
@ -419,7 +420,7 @@ if (! $error && $action == 'writebookkeeping') {
}
}
}
// Third party
if (! $errorforline)
{
@ -440,7 +441,7 @@ if (! $error && $action == 'writebookkeeping') {
$bookkeeping->code_journal = $journal;
$bookkeeping->fk_user_author = $user->id;
$bookkeeping->date_create = $now;
if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution
$bookkeeping->code_tiers = '';
$bookkeeping->numero_compte = $k;
@ -459,7 +460,7 @@ if (! $error && $action == 'writebookkeeping') {
$bookkeeping->code_tiers = $tabcompany[$key]['code_compta'];
$bookkeeping->numero_compte = $k;
} else if ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice
$sqlmid = 'SELECT facf.ref_supplier,facf.ref';
$sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf ";
$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid";
@ -479,7 +480,7 @@ if (! $error && $action == 'writebookkeeping') {
//$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
$bookkeeping->numero_compte = 'CodeNotDef';
}
$result = $bookkeeping->create($user);
if ($result < 0) {
if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists
@ -498,7 +499,7 @@ if (! $error && $action == 'writebookkeeping') {
}
}
}
if (! $errorforline)
{
$db->commit();
@ -520,7 +521,7 @@ if (! $error && $action == 'writebookkeeping') {
{
setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
}
$action = '';
}
@ -542,10 +543,10 @@ if ($action == 'export_csv') {
$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
$reflabel = $val["ref"];
if ($reflabel == '(SupplierInvoicePayment)') {
if ($reflabel == '(SupplierInvoicePayment)' || $reflabel == '(SupplierInvoicePaymentBack)') {
$reflabel = $langs->trans('Supplier');
}
if ($reflabel == '(CustomerInvoicePayment)') {
if ($reflabel == '(CustomerInvoicePayment)' || $reflabel == '(CustomerInvoicePaymentBack)') {
$reflabel = $langs->trans('Customer');
}
if ($reflabel == '(SocialContributionPayment)') {
@ -560,7 +561,7 @@ if ($action == 'export_csv') {
if ($reflabel == '(ExpenseReportPayment)') {
$reflabel = $langs->trans('Employee');
}
$companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name'];
@ -704,7 +705,7 @@ if (empty($action) || $action == 'view') {
$invoicestatic = new Facture($db);
$invoicesupplierstatic = new FactureFournisseur($db);
$expensereportstatic = new ExpenseReport($db);
llxHeader('', $langs->trans("FinanceJournal"));
$nom = $langs->trans("FinanceJournal") . ' - ' . $bank_code_journal->getNomUrl(1);
@ -714,7 +715,7 @@ if (empty($action) || $action == 'view') {
$period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
$varlink = 'id_account=' . $id_bank_account;
report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
/*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
@ -726,7 +727,7 @@ if (empty($action) || $action == 'view') {
print '<div class="tabsAction">';
print '<input type="button" class="butAction" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
print '</div>';
// TODO Avoid using js. We can use a direct link with $param
print '
<script type="text/javascript">
@ -769,12 +770,12 @@ if (empty($action) || $action == 'view') {
$date = dol_print_date($db->jdate($val["date"]), 'day');
$reflabel = $val["ref"];
if ($reflabel == '(SupplierInvoicePayment)') {
if ($reflabel == '(SupplierInvoicePayment)' || $reflabel == '(SupplierInvoicePaymentBack)') {
$reflabel = $langs->trans('Supplier');
}
if ($reflabel == '(CustomerInvoicePayment)') {
if ($reflabel == '(CustomerInvoicePayment)' || $reflabel == '(CustomerInvoicePaymentBack)') {
$reflabel = $langs->trans('Customer');
}
}
if ($reflabel == '(SocialContributionPayment)') {
$reflabel = $langs->trans('SocialContribution');
}
@ -787,7 +788,7 @@ if (empty($action) || $action == 'view') {
if ($reflabel == '(ExpenseReportPayment)') {
$reflabel = $langs->trans('Employee');
}
$ref=$reflabel;
if ($tabtype[$key] == 'payment')
{
@ -837,7 +838,7 @@ if (empty($action) || $action == 'view') {
$invoicestatic->ref = $val["ref"];
$invoicestatic->type = $val["type"];*/
// Bank
foreach ( $tabbq[$key] as $k => $mt )
foreach ( $tabbq[$key] as $k => $mt )
{
print "<tr " . $bc[$var] . ">";
print "<td><!-- Bank bank.rowid=".$key."--></td>";
@ -896,7 +897,7 @@ if (empty($action) || $action == 'view') {
{
print '<span class="error">'.$langs->trans("WaitAccountNotDefined").'</span>';
}
else print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE);
else print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE);
print "</td>";
print "<td>" . $reflabel . "</td>";
print "<td>&nbsp;</td>";

View File

@ -102,7 +102,7 @@ $sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int');
$pageplusone = GETPOST("pageplusone",'int');
if ($pageplusone) $page = $pageplusone - 1;
if ($page == -1) { $page = 0; }
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
@ -130,7 +130,7 @@ if ($id > 0 || ! empty($ref))
$contextpage='banktransactionlist'.(empty($object->ref)?'':'-'.$object->id);
//var_dump($contextpage);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('banktransactionlist', $contextpage));
$extrafields = new ExtraFields($db);
@ -580,6 +580,7 @@ if ($resql)
print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="page" value="'.$page.'">';
print '<input type="hidden" name="id" value="'.$id.'">';
print '<input type="hidden" name="ref" value="'.$ref.'">';
if (GETPOST('bid')) print '<input type="hidden" name="bid" value="'.GETPOST("bid").'">';
@ -1212,6 +1213,7 @@ if ($resql)
{
print '<td align="right">-</td>';
}
if (! $i) $totalarray['nbfield']++;
}
if (! empty($arrayfields['b.num_releve']['checked']))

View File

@ -1141,7 +1141,26 @@ class pdf_crabe extends ModelePDFFactures
}
//}
// VAT
// Situations totals migth be wrong on huge amounts
if ($object->situation_cycle_ref && $object->situation_counter > 1) {
$sum_pdf_tva = 0;
foreach($this->tva as $tvakey => $tvaval){
$sum_pdf_tva+=$tvaval; // sum VAT amounts to compare to object
}
if($sum_pdf_tva!=$object->total_tva) { // apply coef to recover the VAT object amount (the good one)
$coef_fix_tva = $object->total_tva / $sum_pdf_tva;
foreach($this->tva as $tvakey => $tvaval) {
$this->tva[$tvakey]=$tvaval * $coef_fix_tva;
}
}
}
foreach($this->tva as $tvakey => $tvaval)
{
if ($tvakey != 0) // On affiche pas taux 0

View File

@ -134,7 +134,7 @@ CREATE TABLE llx_product_lot_extrafields
ALTER TABLE llx_product_lot_extrafields ADD INDEX idx_product_lot_extrafields (fk_object);
ALTER TABLE llx_website_page MODIFY content MEDIUMTEXT;
ALTER TABLE llx_website_page MODIFY COLUMN content MEDIUMTEXT;
CREATE TABLE llx_product_warehouse_properties
(
@ -160,7 +160,7 @@ ALTER TABLE llx_accounting_account ADD UNIQUE INDEX uk_accounting_account (accou
ALTER TABLE llx_expensereport_det ADD COLUMN fk_code_ventilation integer DEFAULT 0;
ALTER TABLE llx_c_payment_term change fdm type_cdr tinyint;
ALTER TABLE llx_c_payment_term CHANGE COLUMN fdm type_cdr tinyint;
ALTER TABLE llx_facturedet ADD COLUMN vat_src_code varchar(10) DEFAULT '' AFTER tva_tx;
@ -173,11 +173,10 @@ ALTER TABLE llx_supplier_proposaldet ADD COLUMN vat_src_code varchar(10) DEFAULT
ALTER TABLE llx_supplier_proposaldet ADD COLUMN fk_unit integer DEFAULT NULL;
ALTER TABLE llx_contratdet ADD COLUMN vat_src_code varchar(10) DEFAULT '' AFTER tva_tx;
ALTER TABLE llx_c_payment_term change fdm type_cdr tinyint;
ALTER TABLE llx_c_payment_term CHANGE COLUMN fdm type_cdr TINYINT;
ALTER TABLE llx_entrepot ADD COLUMN fk_parent integer DEFAULT 0;
create table llx_resource_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
@ -206,6 +205,8 @@ ALTER TABLE llx_overwrite_trans ADD COLUMN entity integer DEFAULT 1 NOT NULL AFT
ALTER TABLE llx_mailing_cibles ADD COLUMN error_text varchar(255);
ALTER TABLE llx_c_actioncomm MODIFY COLUMN type varchar(50) DEFAULT 'system' NOT NULL;
-- VPGSQL8.2 ALTER TABLE llx_c_actioncomm ALTER COLUMN type SET DEFAULT 'system';
-- VPGSQL8.2 ALTER TABLE llx_c_actioncomm ALTER COLUMN type SET NOT NULL;
create table llx_user_employment
(
@ -240,12 +241,12 @@ ALTER TABLE llx_expensereport ADD INDEX idx_expensereport_fk_refuse (fk_user_app
DELETE FROM llx_actioncomm_resources WHERE fk_actioncomm not in (select id from llx_actioncomm);
-- Sequence to removed duplicated values of llx_links. Use serveral times if you still have duplicate.
drop table tmp_links_double;
DROP TABLE tmp_links_double;
--select objectid, label, max(rowid) as max_rowid, count(rowid) as count_rowid from llx_links where label is not null group by objectid, label having count(rowid) >= 2;
create table tmp_links_double as (select objectid, label, max(rowid) as max_rowid, count(rowid) as count_rowid from llx_links where label is not null group by objectid, label having count(rowid) >= 2);
CREATE TABLE tmp_links_double AS (SELECT objectid, label, MAX(rowid) AS max_rowid, COUNT(rowid) AS count_rowid FROM llx_links WHERE label IS NOT NULL GROUP BY objectid, label HAVING COUNT(rowid) >= 2);
--select * from tmp_links_double;
delete from llx_links where (rowid, label) in (select max_rowid, label from tmp_links_double); --update to avoid duplicate, delete to delete
drop table tmp_links_double;
DELETE FROM llx_links WHERE (rowid, label) IN (SELECT max_rowid, label FROM tmp_links_double); --update to avoid duplicate, delete to delete
DROP TABLE tmp_links_double;
ALTER TABLE llx_links ADD UNIQUE INDEX uk_links (objectid,label);
@ -256,8 +257,7 @@ ALTER TABLE llx_projet_task ADD UNIQUE INDEX uk_projet_task_ref (ref, entity);
ALTER TABLE llx_contrat ADD COLUMN fk_user_modif integer;
update llx_accounting_account set account_parent = 0 where account_parent = '';
UPDATE llx_accounting_account SET account_parent = 0 WHERE account_parent = '';
-- VMYSQL4.3 ALTER TABLE llx_product_price MODIFY COLUMN date_price DATETIME NULL;
-- VPGSQL8.2 ALTER TABLE llx_product_price ALTER COLUMN date_price DROP NOT NULL;
@ -268,10 +268,8 @@ ALTER TABLE llx_product_customer_price ADD COLUMN default_vat_code varchar(10) a
ALTER TABLE llx_product_customer_price_log ADD COLUMN default_vat_code varchar(10) after tva_tx;
ALTER TABLE llx_product_fournisseur_price ADD COLUMN default_vat_code varchar(10) after tva_tx;
ALTER TABLE llx_events MODIFY COLUMN ip varchar(250);
UPDATE llx_bank SET label= '(SupplierInvoicePayment)' WHERE label= 'Règlement fournisseur';
UPDATE llx_bank SET label= '(CustomerInvoicePayment)' WHERE label= 'Règlement client';

View File

@ -516,7 +516,8 @@ if (empty($reshook))
$error = 0;
// Set if we used free entry or predefined product
$predef='';
$predef='';
$ref_fourn = GETPOST('fourn_ref');
$product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
$date_start=dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
$date_end=dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
@ -604,7 +605,7 @@ if (empty($reshook))
$price_base_type = $productsupplier->fourn_price_base_type;
$type = $productsupplier->type;
$label = $productsupplier->label;
$desc = $productsupplier->description;
$desc = $productsupplier->description;
if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc);
$tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice'));

View File

@ -2801,6 +2801,7 @@ class SupplierProposalLine extends CommonObjectLine
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
if (empty($this->fk_unit)) $this->fk_unit=0;
if (empty($this->subprice)) $this->subprice=0;
if (empty($this->pa_ht)) $this->pa_ht=0;
@ -2985,6 +2986,7 @@ class SupplierProposalLine extends CommonObjectLine
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
if (empty($this->fk_unit)) $this->fk_unit=0;
if (empty($this->subprice)) $this->subprice=0;
if (empty($this->pa_ht)) $this->pa_ht=0;

View File

@ -104,7 +104,7 @@ function migrate_product_photospath($product)
global $conf;
$dir = $conf->product->multidir_output[$product->entity];
$origin = $dir .'/'. get_exdir($product->id,2) . $product->id ."/photos";
$origin = $dir .'/'. get_exdir($product->id,2,0,0,$product,'product') . $product->id ."/photos";
$destin = $dir.'/'.dol_sanitizeFileName($product->ref);
$error = 0;