--- /tmp/dsg/dolibarr/htdocs/compta/tva/github_card.php +++ /tmp/dsg/dolibarr/htdocs/compta/tva/client_card.php @@ -73,43 +73,43 @@ if ($action == 'setdatev' && $user->rights->tax->charges->creer) { - $object->fetch($id); + $object->fetch($id); + $object->datev = $datev; + $result = $object->update($user); + if ($result < 0) dol_print_error($db, $object->error); + + $action = ''; +} + +if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) +{ + $error = 0; + + $object->accountid = GETPOST("accountid", 'int'); + $object->type_payment = GETPOST("type_payment", 'alphanohtml'); + $object->num_payment = GETPOST("num_payment", 'alphanohtml'); + $object->datev = $datev; - $result = $object->update($user); - if ($result < 0) dol_print_error($db, $object->error); - - $action = ''; -} - -if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) -{ - $error = 0; - - $object->accountid = GETPOST("accountid", 'int'); - $object->type_payment = GETPOST("type_payment", 'alphanohtml'); - $object->num_payment = GETPOST("num_payment", 'alphanohtml'); - - $object->datev = $datev; - $object->datep = $datep; + $object->datep = $datep; $amount = price2num(GETPOST("amount", 'alpha')); if ($refund == 1) { $amount = -$amount; } - $object->amount = $amount; + $object->amount = $amount; $object->label = GETPOST("label", 'alpha'); - $object->note_private = GETPOST("note", 'restricthtml'); - + $object->note = GETPOST("note", 'none'); + + if (empty($object->datev)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateValue")), null, 'errors'); + $error++; + } if (empty($object->datep)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors'); $error++; } - if (empty($object->datev)) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors'); - $error++; - } if (empty($object->type_payment) || $object->type_payment < 0) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors'); @@ -125,13 +125,15 @@ { $db->begin(); - $ret = $object->addPayment($user); + $ret = $object->addPayment($user); if ($ret > 0) { $db->commit(); header("Location: list.php"); exit; - } else { + } + else + { $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); $action = "create"; @@ -143,15 +145,15 @@ if ($action == 'delete') { - $result = $object->fetch($id); + $result = $object->fetch($id); if ($object->rappro == 0) { - $db->begin(); - - $ret = $object->delete($user); - if ($ret > 0) - { + $db->begin(); + + $ret = $object->delete($user); + if ($ret > 0) + { if ($object->fk_bank) { $accountline = new AccountLine($db); @@ -164,16 +166,22 @@ $db->commit(); header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php'); exit; - } else { + } + else + { $object->error = $accountline->error; $db->rollback(); setEventMessages($object->error, $object->errors, 'errors'); } - } else { - $db->rollback(); - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { + } + else + { + $db->rollback(); + setEventMessages($object->error, $object->errors, 'errors'); + } + } + else + { $mesg = 'Error try do delete a line linked to a conciliated bank transaction'; setEventMessages($mesg, null, 'errors'); } @@ -207,9 +215,9 @@ print load_fiche_titre($langs->trans("VAT").' - '.$langs->trans("New")); if (!empty($conf->use_javascript_ajax)) - { - print "\n".'<script type="text/javascript" language="javascript">'; - print '$(document).ready(function () { + { + print "\n".'<script type="text/javascript" language="javascript">'; + print '$(document).ready(function () { $("#radiopayment").click(function() { $("#label").val($(this).data("label")); @@ -222,40 +230,40 @@ print '</script>'."\n"; } - print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formvat" method="post">'; - print '<input type="hidden" name="token" value="'.newToken().'">'; - print '<input type="hidden" name="action" value="add">'; - - print '<div id="selectmethod">'; - print '<div class="hideonsmartphone float">'; - print $langs->trans("Type").': '; - print '</div>'; - print '<label for="radiopayment">'; - print '<input type="radio" id="radiopayment" data-label="'.$langs->trans('VATPayment').'" class="flat" name="refund" value="0"'.($refund ? '' : ' checked="checked"').'>'; - print ' '; - print $langs->trans("Payment"); - print '</label>'; - print ' '; - print '<label for="radiorefund">'; - print '<input type="radio" id="radiorefund" data-label="'.$langs->trans('VATRefund').'" class="flat" name="refund" value="1"'.($refund ? ' checked="checked"' : '').'>'; - print ' '; - print $langs->trans("PaymentBack"); - print '</label>'; - print '</div>'; - print "<br>\n"; - - print dol_get_fiche_head(); - - print '<table class="border centpercent">'; - - print "<tr>"; - print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>'; - print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1); - print '</td></tr>'; - - print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>'; - print $form->selectDate((GETPOST("datevmonth", 'int') ? $datev : -1), "datev", '', '', '', 'add', 1, 1); - print '</td></tr>'; + print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formvat" method="post">'; + print '<input type="hidden" name="token" value="'.newToken().'">'; + print '<input type="hidden" name="action" value="add">'; + + print '<div id="selectmethod">'; + print '<div class="hideonsmartphone float">'; + print $langs->trans("Type").': '; + print '</div>'; + print '<label for="radiopayment">'; + print '<input type="radio" id="radiopayment" data-label="'.$langs->trans('VATPayment').'" class="flat" name="refund" value="0"'.($refund ? '' : ' checked="checked"').'>'; + print ' '; + print $langs->trans("Payment"); + print '</label>'; + print ' '; + print '<label for="radiorefund">'; + print '<input type="radio" id="radiorefund" data-label="'.$langs->trans('VATRefund').'" class="flat" name="refund" value="1"'.($refund ? ' checked="checked"' : '').'>'; + print ' '; + print $langs->trans("Refund"); + print '</label>'; + print '</div>'; + print "<br>\n"; + + dol_fiche_head(); + + print '<table class="border centpercent">'; + + print "<tr>"; + print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>'; + print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1); + print '</td></tr>'; + + print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>'; + print $form->selectDate((GETPOST("datevmonth", 'int') ? $datev : -1), "datev", '', '', '', 'add', 1, 1); + print '</td></tr>'; // Label if ($refund == 1) { @@ -268,14 +276,14 @@ // Amount print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount", "alpha").'"></td></tr>'; - if (!empty($conf->banque->enabled)) - { + if (!empty($conf->banque->enabled)) + { print '<tr><td class="fieldrequired">'.$langs->trans("BankAccount").'</td><td>'; $form->select_comptes(GETPOST("accountid", 'int'), "accountid", 0, "courant=1", 2); // List of bank account available - print '</td></tr>'; - } - - // Type payment + print '</td></tr>'; + } + + // Type payment print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>'; $form->select_types_paiements(GETPOST("type_payment"), "type_payment"); print "</td>\n"; @@ -286,22 +294,22 @@ print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>'; print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n"; - // Other attributes - $parameters = array(); - $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - - print '</table>'; - - print dol_get_fiche_end(); + // Other attributes + $parameters = array(); + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + print '</table>'; + + dol_fiche_end(); print '<div class="center">'; - print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">'; + print '<input type="submit" class="button" value="'.$langs->trans("Save").'">'; print ' '; - print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">'; + print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">'; print '</div>'; - print '</form>'; + print '</form>'; } // View mode @@ -309,7 +317,7 @@ { $head = vat_prepare_head($object); - print dol_get_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment'); + dol_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment'); $morehtmlref = '<div class="refidno">'; // Label of social contribution @@ -369,7 +377,7 @@ print '</div>'; - print dol_get_fiche_end(); + dol_fiche_end(); /* * Action buttons @@ -379,11 +387,15 @@ { if (!empty($user->rights->tax->charges->supprimer)) { - print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>'; - } else { + print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a></div>'; + } + else + { print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a></div>'; } - } else { + } + else + { print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a></div>'; } print "</div>"; --- /tmp/dsg/dolibarr/htdocs/compta/tva/github_clients.php +++ /tmp/dsg/dolibarr/htdocs/compta/tva/client_clients.php @@ -53,10 +53,10 @@ if (empty($year)) { $year_current = $current_date['year']; - $year_start = $year_current; + $year_start = $year_current; } else { - $year_current = $year; - $year_start = $year; + $year_current = $year; + $year_start = $year; } $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear")); @@ -64,35 +64,41 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end { $q = GETPOST("q", "int"); - if (empty($q)) - { - if (GETPOST("month", 'int')) { $date_start = dol_get_first_day($year_start, GETPOST("month", 'int'), false); $date_end = dol_get_last_day($year_start, GETPOST("month", 'int'), false); } else { - if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { // quaterly vat, we take last past complete quarter - $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm'); - $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1; - } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat - if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) { - if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year - $year_start--; - } - } else { - if (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) < 6) { // If perdio started from less than 6 years, we show past year - $year_start--; - } - } - $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false); - $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1; - } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month - $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm'); - $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1; - } - } - } else { - if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); } - if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); } - if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); } - if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); } - } + if (empty($q)) + { + if (GETPOST("month", 'int')) { $date_start = dol_get_first_day($year_start, GETPOST("month", 'int'), false); $date_end = dol_get_last_day($year_start, GETPOST("month", 'int'), false); } + else + { + if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { // quaterly vat, we take last past complete quarter + $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm'); + $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1; + } + elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat + if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) { + if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year + $year_start--; + } + } else { + if (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) < 6) { // If perdio started from less than 6 years, we show past year + $year_start--; + } + } + $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false); + $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1; + } + elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month + $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm'); + $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1; + } + } + } + else + { + if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); } + if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); } + if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); } + if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); } + } } $min = price2num(GETPOST("min", "alpha")); @@ -124,18 +130,17 @@ $payment_static = new Paiement($db); $paymentfourn_static = new PaiementFourn($db); $paymentexpensereport_static = new PaymentExpenseReport($db); -$user_static = new User($db); $morequerystring = ''; $listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday'); foreach ($listofparams as $param) { - if (GETPOST($param) != '') $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param); + if (GETPOST($param) != '') $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param); } $special_report = false; if (isset($_REQUEST['extra_report']) && $_REQUEST['extra_report'] == 1) { - $special_report = true; + $special_report = true; } llxHeader('', $langs->trans("VATReport"), '', '', 0, 0, '', '', $morequerystring); @@ -152,24 +157,24 @@ if ($modetax == 0) $calcmode = $langs->trans('OptionVATDefault'); if ($modetax == 1) $calcmode = $langs->trans('OptionVATDebitOption'); if ($modetax == 2) $calcmode = $langs->trans('OptionPaymentForProductAndServices'); -$calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')</span>'; +$calcmode .= '<br>('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')'; // Set period $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); $prevyear = $year_start; $prevquarter = $q; if ($prevquarter > 1) { - $prevquarter--; + $prevquarter--; } else { - $prevquarter = 4; - $prevyear--; + $prevquarter = 4; + $prevyear--; } $nextyear = $year_start; $nextquarter = $q; if ($nextquarter < 4) { - $nextquarter++; + $nextquarter++; } else { - $nextquarter = 1; - $nextyear++; + $nextquarter = 1; + $nextyear++; } $builddate = dol_now(); @@ -178,7 +183,7 @@ if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') $description .= '<br>'.$langs->trans("RulesVATDueServices"); if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') $description .= '<br>'.$langs->trans("RulesVATInServices"); if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - $description .= '<br>'.$langs->trans("DepositsAreNotIncluded"); + $description .= '<br>'.$langs->trans("DepositsAreNotIncluded"); } if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description .= '<br>'.$langs->trans("ThisIsAnEstimatedValue"); @@ -186,15 +191,15 @@ $description .= ($description ? '<br>' : '').$fsearch; if (!empty($conf->global->TAX_REPORT_EXTRA_REPORT)) { - $description .= '<br>'; - $description .= '<input type="radio" name="extra_report" value="0" '.($special_report ? '' : 'checked="checked"').'> '; - $description .= $langs->trans('SimpleReport'); - $description .= '</input>'; - $description .= '<br>'; - $description .= '<input type="radio" name="extra_report" value="1" '.($special_report ? 'checked="checked"' : '').'> '; - $description .= $langs->trans('AddExtraReport'); - $description .= '</input>'; - $description .= '<br>'; + $description .= '<br>'; + $description .= '<input type="radio" name="extra_report" value="0" '.($special_report ? '' : 'checked="checked"').'> '; + $description .= $langs->trans('SimpleReport'); + $description .= '</input>'; + $description .= '<br>'; + $description .= '<input type="radio" name="extra_report" value="1" '.($special_report ? 'checked="checked"' : '').'> '; + $description .= $langs->trans('AddExtraReport'); + $description .= '</input>'; + $description .= '<br>'; } $elementcust = $langs->trans("CustomersInvoices"); @@ -202,13 +207,13 @@ $namerate = $langs->trans("VATRate"); $amountcust = $langs->trans("AmountHT"); if ($mysoc->tva_assuj) { - $vatcust .= ' ('.$langs->trans("StatusToPay").')'; + $vatcust .= ' ('.$langs->trans("StatusToPay").')'; } $elementsup = $langs->trans("SuppliersInvoices"); $productsup = $langs->trans("Description"); $amountsup = $langs->trans("AmountHT"); if ($mysoc->tva_assuj) { - $vatsup .= ' ('.$langs->trans("ToGetBack").')'; + $vatsup .= ' ('.$langs->trans("ToGetBack").')'; } report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode); @@ -217,7 +222,7 @@ // VAT Received -print '<div class="div-table-responsive">'; + print "<table class=\"noborder\" width=\"100%\">"; $y = $year_current; @@ -231,533 +236,539 @@ if (!is_array($x_coll) || !is_array($x_paye)) { - $langs->load("errors"); - if ($x_coll == -1) { - print '<tr><td colspan="'.$columns.'">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>'; - } elseif ($x_coll == -2) { - print '<tr><td colspan="'.$columns.'">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'; - } else { - print '<tr><td colspan="'.$columns.'">'.$langs->trans("Error").'</td></tr>'; - } + $langs->load("errors"); + if ($x_coll == -1) { + print '<tr><td colspan="'.$columns.'">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>'; + } elseif ($x_coll == -2) { + print '<tr><td colspan="'.$columns.'">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'; + } else { + print '<tr><td colspan="'.$columns.'">'.$langs->trans("Error").'</td></tr>'; + } } else { - $x_both = array(); - //now, from these two arrays, get another array with one rate per line - foreach (array_keys($x_coll) as $my_coll_thirdpartyid) - { - $x_both[$my_coll_thirdpartyid]['coll']['totalht'] = $x_coll[$my_coll_thirdpartyid]['totalht']; - $x_both[$my_coll_thirdpartyid]['coll']['vat'] = $x_coll[$my_coll_thirdpartyid]['vat']; - $x_both[$my_coll_thirdpartyid]['paye']['totalht'] = 0; - $x_both[$my_coll_thirdpartyid]['paye']['vat'] = 0; - $x_both[$my_coll_thirdpartyid]['coll']['links'] = ''; - $x_both[$my_coll_thirdpartyid]['coll']['detail'] = array(); - foreach ($x_coll[$my_coll_thirdpartyid]['facid'] as $id=>$dummy) { - $invoice_customer->id = $x_coll[$my_coll_thirdpartyid]['facid'][$id]; - $invoice_customer->ref = $x_coll[$my_coll_thirdpartyid]['facnum'][$id]; - $invoice_customer->type = $x_coll[$my_coll_thirdpartyid]['type'][$id]; - $company_static->fetch($x_coll[$my_coll_thirdpartyid]['company_id'][$id]); - $x_both[$my_coll_thirdpartyid]['coll']['detail'][] = array( - 'id' =>$x_coll[$my_coll_thirdpartyid]['facid'][$id], - 'descr' =>$x_coll[$my_coll_thirdpartyid]['descr'][$id], - 'pid' =>$x_coll[$my_coll_thirdpartyid]['pid'][$id], - 'pref' =>$x_coll[$my_coll_thirdpartyid]['pref'][$id], - 'ptype' =>$x_coll[$my_coll_thirdpartyid]['ptype'][$id], - 'payment_id'=>$x_coll[$my_coll_thirdpartyid]['payment_id'][$id], - 'payment_amount'=>$x_coll[$my_coll_thirdpartyid]['payment_amount'][$id], - 'ftotal_ttc'=>$x_coll[$my_coll_thirdpartyid]['ftotal_ttc'][$id], - 'dtotal_ttc'=>$x_coll[$my_coll_thirdpartyid]['dtotal_ttc'][$id], - 'dtype' =>$x_coll[$my_coll_thirdpartyid]['dtype'][$id], - 'drate' =>$x_coll[$my_coll_thirdpartyid]['drate'][$id], - 'datef' =>$x_coll[$my_coll_thirdpartyid]['datef'][$id], - 'datep' =>$x_coll[$my_coll_thirdpartyid]['datep'][$id], - 'company_link'=>$company_static->getNomUrl(1, '', 20), - 'ddate_start'=>$x_coll[$my_coll_thirdpartyid]['ddate_start'][$id], - 'ddate_end' =>$x_coll[$my_coll_thirdpartyid]['ddate_end'][$id], - 'totalht' =>$x_coll[$my_coll_thirdpartyid]['totalht_list'][$id], - 'vat' =>$x_coll[$my_coll_thirdpartyid]['vat_list'][$id], - 'link' =>$invoice_customer->getNomUrl(1, '', 12) - ); - } - } - // tva paid - foreach (array_keys($x_paye) as $my_paye_thirdpartyid) { - $x_both[$my_paye_thirdpartyid]['paye']['totalht'] = $x_paye[$my_paye_thirdpartyid]['totalht']; - $x_both[$my_paye_thirdpartyid]['paye']['vat'] = $x_paye[$my_paye_thirdpartyid]['vat']; - if (!isset($x_both[$my_paye_thirdpartyid]['coll']['totalht'])) { - $x_both[$my_paye_thirdpartyid]['coll']['totalht'] = 0; - $x_both[$my_paye_thirdpartyid]['coll']['vat'] = 0; - } - $x_both[$my_paye_thirdpartyid]['paye']['links'] = ''; - $x_both[$my_paye_thirdpartyid]['paye']['detail'] = array(); - - foreach ($x_paye[$my_paye_thirdpartyid]['facid'] as $id=>$dummy) - { - // ExpenseReport - if ($x_paye[$my_paye_thirdpartyid]['ptype'][$id] == 'ExpenseReportPayment') - { - $expensereport->id = $x_paye[$my_paye_thirdpartyid]['facid'][$id]; - $expensereport->ref = $x_paye[$my_paye_thirdpartyid]['facnum'][$id]; - $expensereport->type = $x_paye[$my_paye_thirdpartyid]['type'][$id]; - - $x_both[$my_paye_thirdpartyid]['paye']['detail'][] = array( - 'id' =>$x_paye[$my_paye_thirdpartyid]['facid'][$id], - 'descr' =>$x_paye[$my_paye_thirdpartyid]['descr'][$id], - 'pid' =>$x_paye[$my_paye_thirdpartyid]['pid'][$id], - 'pref' =>$x_paye[$my_paye_thirdpartyid]['pref'][$id], - 'ptype' =>$x_paye[$my_paye_thirdpartyid]['ptype'][$id], - 'payment_id' =>$x_paye[$my_paye_thirdpartyid]['payment_id'][$id], - 'payment_amount' =>$x_paye[$my_paye_thirdpartyid]['payment_amount'][$id], - 'ftotal_ttc' =>price2num($x_paye[$my_paye_thirdpartyid]['ftotal_ttc'][$id]), - 'dtotal_ttc' =>price2num($x_paye[$my_paye_thirdpartyid]['dtotal_ttc'][$id]), - 'dtype' =>$x_paye[$my_paye_thirdpartyid]['dtype'][$id], - 'drate' =>$x_paye[$my_coll_thirdpartyid]['drate'][$id], - 'ddate_start' =>$x_paye[$my_paye_thirdpartyid]['ddate_start'][$id], - 'ddate_end' =>$x_paye[$my_paye_thirdpartyid]['ddate_end'][$id], - 'totalht' =>price2num($x_paye[$my_paye_thirdpartyid]['totalht_list'][$id]), - 'vat' =>$x_paye[$my_paye_thirdpartyid]['vat_list'][$id], - 'link' =>$expensereport->getNomUrl(1) - ); - } else { - $invoice_supplier->id = $x_paye[$my_paye_thirdpartyid]['facid'][$id]; - $invoice_supplier->ref = $x_paye[$my_paye_thirdpartyid]['facnum'][$id]; - $invoice_supplier->type = $x_paye[$my_paye_thirdpartyid]['type'][$id]; - $company_static->fetch($x_paye[$my_paye_thirdpartyid]['company_id'][$id]); - $x_both[$my_paye_thirdpartyid]['paye']['detail'][] = array( - 'id' =>$x_paye[$my_paye_thirdpartyid]['facid'][$id], - 'descr' =>$x_paye[$my_paye_thirdpartyid]['descr'][$id], - 'pid' =>$x_paye[$my_paye_thirdpartyid]['pid'][$id], - 'pref' =>$x_paye[$my_paye_thirdpartyid]['pref'][$id], - 'ptype' =>$x_paye[$my_paye_thirdpartyid]['ptype'][$id], - 'payment_id'=>$x_paye[$my_paye_thirdpartyid]['payment_id'][$id], - 'payment_amount'=>$x_paye[$my_paye_thirdpartyid]['payment_amount'][$id], - 'ftotal_ttc'=>price2num($x_paye[$my_paye_thirdpartyid]['ftotal_ttc'][$id]), - 'dtotal_ttc'=>price2num($x_paye[$my_paye_thirdpartyid]['dtotal_ttc'][$id]), - 'dtype' =>$x_paye[$my_paye_thirdpartyid]['dtype'][$id], - 'drate' =>$x_paye[$my_coll_thirdpartyid]['drate'][$id], - 'datef' =>$x_paye[$my_paye_thirdpartyid]['datef'][$id], - 'datep' =>$x_paye[$my_paye_thirdpartyid]['datep'][$id], - 'company_link'=>$company_static->getNomUrl(1, '', 20), - 'ddate_start'=>$x_paye[$my_paye_thirdpartyid]['ddate_start'][$id], - 'ddate_end' =>$x_paye[$my_paye_thirdpartyid]['ddate_end'][$id], - 'totalht' =>price2num($x_paye[$my_paye_thirdpartyid]['totalht_list'][$id]), - 'vat' =>$x_paye[$my_paye_thirdpartyid]['vat_list'][$id], - 'link' =>$invoice_supplier->getNomUrl(1, '', 12) - ); - } - } - } - //now we have an array (x_both) indexed by rates for coll and paye - - - //print table headers for this quadri - incomes first - - $x_coll_sum = 0; - $x_coll_ht = 0; - $x_paye_sum = 0; - $x_paye_ht = 0; - - $span = $columns; - if ($modetax != 1) $span += 2; - - //print '<tr><td colspan="'.($span+1).'">'..')</td></tr>'; - - // Customers invoices - print '<tr class="liste_titre">'; - print '<td class="left">'.$elementcust.'</td>'; - print '<td class="left">'.$langs->trans("DateInvoice").'</td>'; - if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '<td class="left">'.$langs->trans("DatePayment").'</td>'; - else print '<td></td>'; - print '<td class="right">'.$namerate.'</td>'; - print '<td class="left">'.$productcust.'</td>'; - if ($modetax != 1) - { - print '<td class="right">'.$amountcust.'</td>'; - print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>'; - } - print '<td class="right">'.$langs->trans("AmountHTVATRealReceived").'</td>'; - print '<td class="right">'.$vatcust.'</td>'; - print '</tr>'; - - $action = "tvadetail"; - $parameters["mode"] = $modetax; - $parameters["start"] = $date_start; - $parameters["end"] = $date_end; - $parameters["type"] = 'vat'; - - $object = array(&$x_coll, &$x_paye, &$x_both); - // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array - $hookmanager->initHooks(array('externalbalance')); - $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks - - foreach (array_keys($x_coll) as $thirdparty_id) { - $subtot_coll_total_ht = 0; - $subtot_coll_vat = 0; - - if ($min == 0 || ($min > 0 && $x_both[$thirdparty_id]['coll']['totalht'] > $min)) - { - if (is_array($x_both[$thirdparty_id]['coll']['detail'])) - { - // VAT Rate - print "<tr>"; - print '<td class="tax_rate">'; - if (is_numeric($thirdparty_id)) { - $company_static->fetch($thirdparty_id); - print $langs->trans("ThirdParty").': '.$company_static->getNomUrl(1); - } else { - $tmpid = preg_replace('/userid_/', '', $thirdparty_id); - $user_static->fetch($tmpid); - print $langs->trans("User").': '.$user_static->getNomUrl(1); - } - print '</td><td colspan="'.($span + 1).'"></td>'; - print '</tr>'."\n"; - - foreach ($x_both[$thirdparty_id]['coll']['detail'] as $index => $fields) { - // Define type - // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. - $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - if (!empty($fields['ddate_start'])) { - $type = 1; - } - if (!empty($fields['ddate_end'])) { - $type = 1; - } - - print '<tr class="oddeven">'; - - // Ref - print '<td class="nowrap left">'.$fields['link'].'</td>'; - - // Invoice date - print '<td class="left">'.dol_print_date($fields['datef'], 'day').'</td>'; - - // Payment date - if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') { - print '<td class="left">'.dol_print_date($fields['datep'], 'day').'</td>'; - } else { - print '<td></td>'; - } - - // Rate - print '<td class="right">'.$fields['drate'].'</td>'; - - // Description - print '<td class="left">'; - if ($fields['pid']) { - $product_static->id = $fields['pid']; - $product_static->ref = $fields['pref']; - $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered - print $product_static->getNomUrl(1); - if (dol_string_nohtmltag($fields['descr'])) { - print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - } - } else { - if ($type) { - $text = img_object($langs->trans('Service'), 'service'); - } else { - $text = img_object($langs->trans('Product'), 'product'); - } - if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { - if ($reg[1] == 'DEPOSIT') { - $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); - } elseif ($reg[1] == 'CREDIT_NOTE') { - $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); - } else { - $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); - } - } - print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - - // Show range - print_date_range($fields['ddate_start'], $fields['ddate_end']); - } - print '</td>'; - - // Total HT - if ($modetax != 1) { - print '<td class="nowrap right">'; - print price($fields['totalht']); - if (price2num($fields['ftotal_ttc'])) { - //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; - $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); - //print ' ('.round($ratiolineinvoice*100,2).'%)'; - } - print '</td>'; - } - - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) { - print '<td class="nowrap right">'; - //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc']; - if ($fields['payment_amount'] && $fields['ftotal_ttc']) { - $payment_static->id = $fields['payment_id']; - print $payment_static->getNomUrl(2); - } - if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) { - print $langs->trans("NA"); - } else { - if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - print price(price2num($fields['payment_amount'], 'MT')); - if (isset($fields['payment_amount'])) { - print ' ('.round($ratiopaymentinvoice * 100, 2).'%)'; - } - } - print '</td>'; - } - - // Total collected - print '<td class="nowrap right">'; - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - print price(price2num($temp_ht, 'MT'), 1); - print '</td>'; - - // VAT - print '<td class="nowrap right">'; - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - print price(price2num($temp_vat, 'MT'), 1); - //print price($fields['vat']); - print '</td>'; - print '</tr>'; - - $subtot_coll_total_ht += $temp_ht; - $subtot_coll_vat += $temp_vat; - $x_coll_sum += $temp_vat; - } - } - // Total customers for this vat rate - print '<tr class="liste_total">'; - print '<td colspan="4"></td>'; - print '<td class="right">'.$langs->trans("Total").':</td>'; - if ($modetax != 1) { - print '<td class="nowrap right"> </td>'; - print '<td class="right"> </td>'; - } - print '<td class="right">'.price(price2num($subtot_coll_total_ht, 'MT')).'</td>'; - print '<td class="nowrap right">'.price(price2num($subtot_coll_vat, 'MT')).'</td>'; - print '</tr>'; - } - } - - if (count($x_coll) == 0) // Show a total ine if nothing shown - { - print '<tr class="liste_total">'; - print '<td colspan="4"></td>'; - print '<td class="right">'.$langs->trans("Total").':</td>'; - if ($modetax != 1) { - print '<td class="nowrap right"> </td>'; - print '<td class="right"> </td>'; - } - print '<td class="right">'.price(price2num(0, 'MT')).'</td>'; - print '<td class="nowrap right">'.price(price2num(0, 'MT')).'</td>'; - print '</tr>'; - } - - // Blank line - print '<tr><td colspan="'.($span + 1).'"> </td></tr>'; - - // Print table headers for this quadri - expenses now - print '<tr class="liste_titre liste_titre_topborder">'; - print '<td class="left">'.$elementsup.'</td>'; - print '<td class="left">'.$langs->trans("DateInvoice").'</td>'; - if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td class="left">'.$langs->trans("DatePayment").'</td>'; - else print '<td></td>'; - print '<td class="left">'.$namesup.'</td>'; - print '<td class="left">'.$productsup.'</td>'; - if ($modetax != 1) { - print '<td class="right">'.$amountsup.'</td>'; - print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>'; - } - print '<td class="right">'.$langs->trans("AmountHTVATRealPaid").'</td>'; - print '<td class="right">'.$vatsup.'</td>'; - print '</tr>'."\n"; - - foreach (array_keys($x_paye) as $thirdparty_id) - { - $subtot_paye_total_ht = 0; - $subtot_paye_vat = 0; - - if ($min == 0 || ($min > 0 && $x_both[$thirdparty_id]['paye']['totalht'] > $min)) { - if (is_array($x_both[$thirdparty_id]['paye']['detail'])) { - print "<tr>"; - print '<td class="tax_rate">'; - if (is_numeric($thirdparty_id)) { - $company_static->fetch($thirdparty_id); - print $langs->trans("ThirdParty").': '.$company_static->getNomUrl(1); - } else { - $tmpid = preg_replace('/userid_/', '', $thirdparty_id); - $user_static->fetch($tmpid); - print $langs->trans("User").': '.$user_static->getNomUrl(1); - } - print '<td colspan="'.($span + 1).'"></td>'; - print '</tr>'."\n"; - - foreach ($x_both[$thirdparty_id]['paye']['detail'] as $index => $fields) { - // Define type - // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. - $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - if (!empty($fields['ddate_start'])) { - $type = 1; - } - if (!empty($fields['ddate_end'])) { - $type = 1; - } - - - print '<tr class="oddeven">'; - - // Ref - print '<td class="nowrap left">'.$fields['link'].'</td>'; - - // Invoice date - print '<td class="left">'.dol_print_date($fields['datef'], 'day').'</td>'; - - // Payment date - if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') { - print '<td class="left">'.dol_print_date($fields['datep'], 'day').'</td>'; - } else { - print '<td></td>'; - } - - // Company name - print '<td class="left">'.$fields['company_link'].'</td>'; - - // Description - print '<td class="left">'; - if ($fields['pid']) { - $product_static->id = $fields['pid']; - $product_static->ref = $fields['pref']; - $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered - print $product_static->getNomUrl(1); - if (dol_string_nohtmltag($fields['descr'])) { - print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - } - } else { - if ($type) { - $text = img_object($langs->trans('Service'), 'service'); - } else { - $text = img_object($langs->trans('Product'), 'product'); - } - if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { - if ($reg[1] == 'DEPOSIT') { - $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); - } elseif ($reg[1] == 'CREDIT_NOTE') { - $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); - } else { - $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); - } - } - print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); - - // Show range - print_date_range($fields['ddate_start'], $fields['ddate_end']); - } - print '</td>'; - - // Total HT - if ($modetax != 1) { - print '<td class="nowrap right">'; - print price($fields['totalht']); - if (price2num($fields['ftotal_ttc'])) { - //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; - $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); - //print ' ('.round($ratiolineinvoice*100,2).'%)'; - } - print '</td>'; - } - - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) - { - print '<td class="nowrap right">'; - if ($fields['payment_amount'] && $fields['ftotal_ttc']) - { - $paymentfourn_static->id = $fields['payment_id']; - print $paymentfourn_static->getNomUrl(2); - } - - if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) - { - print $langs->trans("NA"); - } else { - if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - print price(price2num($fields['payment_amount'], 'MT')); - if (isset($fields['payment_amount'])) { - print ' ('.round($ratiopaymentinvoice * 100, 2).'%)'; - } - } - print '</td>'; - } - - // VAT paid - print '<td class="nowrap right">'; - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - print price(price2num($temp_ht, 'MT'), 1); - print '</td>'; - - // VAT - print '<td class="nowrap right">'; - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - print price(price2num($temp_vat, 'MT'), 1); - //print price($fields['vat']); - print '</td>'; - print '</tr>'; - - $subtot_paye_total_ht += $temp_ht; - $subtot_paye_vat += $temp_vat; - $x_paye_sum += $temp_vat; - } - } - // Total suppliers for this vat rate - print '<tr class="liste_total">'; - print '<td colspan="4"></td>'; - print '<td class="right">'.$langs->trans("Total").':</td>'; - if ($modetax != 1) { - print '<td class="nowrap right"> </td>'; - print '<td class="right"> </td>'; - } - print '<td class="right">'.price(price2num($subtot_paye_total_ht, 'MT')).'</td>'; - print '<td class="nowrap right">'.price(price2num($subtot_paye_vat, 'MT')).'</td>'; - print '</tr>'; - } - } - - if (count($x_paye) == 0) { // Show a total line if nothing shown - print '<tr class="liste_total">'; - print '<td colspan="4"></td>'; - print '<td class="right">'.$langs->trans("Total").':</td>'; - if ($modetax != 1) { - print '<td class="nowrap right"> </td>'; - print '<td class="right"> </td>'; - } - print '<td class="right">'.price(price2num(0, 'MT')).'</td>'; - print '<td class="nowrap right">'.price(price2num(0, 'MT')).'</td>'; - print '</tr>'; - } - - // Total to pay - print '<tr><td colspan="'.($span + 2).'"></td></tr>'; - - $diff = $x_coll_sum - $x_paye_sum; - print '<tr class="liste_total">'; - print '<td class="liste_total" colspan="'.($span + 1).'">'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').'</td>'; - print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n"; - print "</tr>\n"; - - $i++; + $x_both = array(); + //now, from these two arrays, get another array with one rate per line + foreach (array_keys($x_coll) as $my_coll_thirdpartyid) + { + $x_both[$my_coll_thirdpartyid]['coll']['totalht'] = $x_coll[$my_coll_thirdpartyid]['totalht']; + $x_both[$my_coll_thirdpartyid]['coll']['vat'] = $x_coll[$my_coll_thirdpartyid]['vat']; + $x_both[$my_coll_thirdpartyid]['paye']['totalht'] = 0; + $x_both[$my_coll_thirdpartyid]['paye']['vat'] = 0; + $x_both[$my_coll_thirdpartyid]['coll']['links'] = ''; + $x_both[$my_coll_thirdpartyid]['coll']['detail'] = array(); + foreach ($x_coll[$my_coll_thirdpartyid]['facid'] as $id=>$dummy) { + $invoice_customer->id = $x_coll[$my_coll_thirdpartyid]['facid'][$id]; + $invoice_customer->ref = $x_coll[$my_coll_thirdpartyid]['facnum'][$id]; + $invoice_customer->type = $x_coll[$my_coll_thirdpartyid]['type'][$id]; + $company_static->fetch($x_coll[$my_coll_thirdpartyid]['company_id'][$id]); + $x_both[$my_coll_thirdpartyid]['coll']['detail'][] = array( + 'id' =>$x_coll[$my_coll_thirdpartyid]['facid'][$id], + 'descr' =>$x_coll[$my_coll_thirdpartyid]['descr'][$id], + 'pid' =>$x_coll[$my_coll_thirdpartyid]['pid'][$id], + 'pref' =>$x_coll[$my_coll_thirdpartyid]['pref'][$id], + 'ptype' =>$x_coll[$my_coll_thirdpartyid]['ptype'][$id], + 'payment_id'=>$x_coll[$my_coll_thirdpartyid]['payment_id'][$id], + 'payment_amount'=>$x_coll[$my_coll_thirdpartyid]['payment_amount'][$id], + 'ftotal_ttc'=>$x_coll[$my_coll_thirdpartyid]['ftotal_ttc'][$id], + 'dtotal_ttc'=>$x_coll[$my_coll_thirdpartyid]['dtotal_ttc'][$id], + 'dtype' =>$x_coll[$my_coll_thirdpartyid]['dtype'][$id], + 'drate' =>$x_coll[$my_coll_thirdpartyid]['drate'][$id], + 'datef' =>$x_coll[$my_coll_thirdpartyid]['datef'][$id], + 'datep' =>$x_coll[$my_coll_thirdpartyid]['datep'][$id], + 'company_link'=>$company_static->getNomUrl(1, '', 20), + 'ddate_start'=>$x_coll[$my_coll_thirdpartyid]['ddate_start'][$id], + 'ddate_end' =>$x_coll[$my_coll_thirdpartyid]['ddate_end'][$id], + 'totalht' =>$x_coll[$my_coll_thirdpartyid]['totalht_list'][$id], + 'vat' =>$x_coll[$my_coll_thirdpartyid]['vat_list'][$id], + 'link' =>$invoice_customer->getNomUrl(1, '', 12) + ); + } + } + // tva paid + foreach (array_keys($x_paye) as $my_paye_thirdpartyid) { + $x_both[$my_paye_thirdpartyid]['paye']['totalht'] = $x_paye[$my_paye_thirdpartyid]['totalht']; + $x_both[$my_paye_thirdpartyid]['paye']['vat'] = $x_paye[$my_paye_thirdpartyid]['vat']; + if (!isset($x_both[$my_paye_thirdpartyid]['coll']['totalht'])) { + $x_both[$my_paye_thirdpartyid]['coll']['totalht'] = 0; + $x_both[$my_paye_thirdpartyid]['coll']['vat'] = 0; + } + $x_both[$my_paye_thirdpartyid]['paye']['links'] = ''; + $x_both[$my_paye_thirdpartyid]['paye']['detail'] = array(); + + foreach ($x_paye[$my_paye_thirdpartyid]['facid'] as $id=>$dummy) + { + // ExpenseReport + if ($x_paye[$my_paye_thirdpartyid]['ptype'][$id] == 'ExpenseReportPayment') + { + $expensereport->id = $x_paye[$my_paye_thirdpartyid]['facid'][$id]; + $expensereport->ref = $x_paye[$my_paye_thirdpartyid]['facnum'][$id]; + $expensereport->type = $x_paye[$my_paye_thirdpartyid]['type'][$id]; + + $x_both[$my_paye_thirdpartyid]['paye']['detail'][] = array( + 'id' =>$x_paye[$my_paye_thirdpartyid]['facid'][$id], + 'descr' =>$x_paye[$my_paye_thirdpartyid]['descr'][$id], + 'pid' =>$x_paye[$my_paye_thirdpartyid]['pid'][$id], + 'pref' =>$x_paye[$my_paye_thirdpartyid]['pref'][$id], + 'ptype' =>$x_paye[$my_paye_thirdpartyid]['ptype'][$id], + 'payment_id' =>$x_paye[$my_paye_thirdpartyid]['payment_id'][$id], + 'payment_amount' =>$x_paye[$my_paye_thirdpartyid]['payment_amount'][$id], + 'ftotal_ttc' =>price2num($x_paye[$my_paye_thirdpartyid]['ftotal_ttc'][$id]), + 'dtotal_ttc' =>price2num($x_paye[$my_paye_thirdpartyid]['dtotal_ttc'][$id]), + 'dtype' =>$x_paye[$my_paye_thirdpartyid]['dtype'][$id], + 'drate' =>$x_paye[$my_coll_thirdpartyid]['drate'][$id], + 'ddate_start' =>$x_paye[$my_paye_thirdpartyid]['ddate_start'][$id], + 'ddate_end' =>$x_paye[$my_paye_thirdpartyid]['ddate_end'][$id], + 'totalht' =>price2num($x_paye[$my_paye_thirdpartyid]['totalht_list'][$id]), + 'vat' =>$x_paye[$my_paye_thirdpartyid]['vat_list'][$id], + 'link' =>$expensereport->getNomUrl(1) + ); + } + else + { + $invoice_supplier->id = $x_paye[$my_paye_thirdpartyid]['facid'][$id]; + $invoice_supplier->ref = $x_paye[$my_paye_thirdpartyid]['facnum'][$id]; + $invoice_supplier->type = $x_paye[$my_paye_thirdpartyid]['type'][$id]; + $company_static->fetch($x_paye[$my_paye_thirdpartyid]['company_id'][$id]); + $x_both[$my_paye_thirdpartyid]['paye']['detail'][] = array( + 'id' =>$x_paye[$my_paye_thirdpartyid]['facid'][$id], + 'descr' =>$x_paye[$my_paye_thirdpartyid]['descr'][$id], + 'pid' =>$x_paye[$my_paye_thirdpartyid]['pid'][$id], + 'pref' =>$x_paye[$my_paye_thirdpartyid]['pref'][$id], + 'ptype' =>$x_paye[$my_paye_thirdpartyid]['ptype'][$id], + 'payment_id'=>$x_paye[$my_paye_thirdpartyid]['payment_id'][$id], + 'payment_amount'=>$x_paye[$my_paye_thirdpartyid]['payment_amount'][$id], + 'ftotal_ttc'=>price2num($x_paye[$my_paye_thirdpartyid]['ftotal_ttc'][$id]), + 'dtotal_ttc'=>price2num($x_paye[$my_paye_thirdpartyid]['dtotal_ttc'][$id]), + 'dtype' =>$x_paye[$my_paye_thirdpartyid]['dtype'][$id], + 'drate' =>$x_paye[$my_coll_thirdpartyid]['drate'][$id], + 'datef' =>$x_paye[$my_paye_thirdpartyid]['datef'][$id], + 'datep' =>$x_paye[$my_paye_thirdpartyid]['datep'][$id], + 'company_link'=>$company_static->getNomUrl(1, '', 20), + 'ddate_start'=>$x_paye[$my_paye_thirdpartyid]['ddate_start'][$id], + 'ddate_end' =>$x_paye[$my_paye_thirdpartyid]['ddate_end'][$id], + 'totalht' =>price2num($x_paye[$my_paye_thirdpartyid]['totalht_list'][$id]), + 'vat' =>$x_paye[$my_paye_thirdpartyid]['vat_list'][$id], + 'link' =>$invoice_supplier->getNomUrl(1, '', 12) + ); + } + } + } + //now we have an array (x_both) indexed by rates for coll and paye + + + //print table headers for this quadri - incomes first + + $x_coll_sum = 0; + $x_coll_ht = 0; + $x_paye_sum = 0; + $x_paye_ht = 0; + + $span = $columns; + if ($modetax != 1) $span += 2; + + //print '<tr><td colspan="'.($span+1).'">'..')</td></tr>'; + + // Customers invoices + print '<tr class="liste_titre">'; + print '<td class="left">'.$elementcust.'</td>'; + print '<td class="left">'.$langs->trans("DateInvoice").'</td>'; + if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '<td class="left">'.$langs->trans("DatePayment").'</td>'; + else print '<td></td>'; + print '<td class="right">'.$namerate.'</td>'; + print '<td class="left">'.$productcust.'</td>'; + if ($modetax != 1) + { + print '<td class="right">'.$amountcust.'</td>'; + print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>'; + } + print '<td class="right">'.$langs->trans("AmountHTVATRealReceived").'</td>'; + print '<td class="right">'.$vatcust.'</td>'; + print '</tr>'; + + $action = "tvadetail"; + $parameters["mode"] = $modetax; + $parameters["start"] = $date_start; + $parameters["end"] = $date_end; + $parameters["type"] = 'vat'; + + $object = array(&$x_coll, &$x_paye, &$x_both); + // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array + $hookmanager->initHooks(array('externalbalance')); + $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks + + foreach (array_keys($x_coll) as $thirdparty_id) { + $subtot_coll_total_ht = 0; + $subtot_coll_vat = 0; + + if ($min == 0 || ($min > 0 && $x_both[$thirdparty_id]['coll']['totalht'] > $min)) + { + if (is_array($x_both[$thirdparty_id]['coll']['detail'])) + { + // VAT Rate + print "<tr>"; + print '<td class="tax_rate">'; + if (is_numeric($thirdparty_id)) { + $company_static->fetch($thirdparty_id); + print $langs->trans("ThirdParty").': '.$company_static->getNomUrl(1); + } else { + $tmpid = preg_replace('/userid_/', '', $thirdparty_id); + $user_static->fetch($tmpid); + print $langs->trans("User").': '.$user_static->getNomUrl(1); + } + print '</td><td colspan="'.($span + 1).'"></td>'; + print '</tr>'."\n"; + + foreach ($x_both[$thirdparty_id]['coll']['detail'] as $index => $fields) { + // Define type + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($fields['ddate_start'])) { + $type = 1; + } + if (!empty($fields['ddate_end'])) { + $type = 1; + } + + print '<tr class="oddeven">'; + + // Ref + print '<td class="nowrap left">'.$fields['link'].'</td>'; + + // Invoice date + print '<td class="left">'.dol_print_date($fields['datef'], 'day').'</td>'; + + // Payment date + if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') { + print '<td class="left">'.dol_print_date($fields['datep'], 'day').'</td>'; + } else { + print '<td></td>'; + } + + // Rate + print '<td class="right">'.$fields['drate'].'</td>'; + + // Description + print '<td class="left">'; + if ($fields['pid']) { + $product_static->id = $fields['pid']; + $product_static->ref = $fields['pref']; + $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered + print $product_static->getNomUrl(1); + if (dol_string_nohtmltag($fields['descr'])) { + print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); + } + } else { + if ($type) { + $text = img_object($langs->trans('Service'), 'service'); + } else { + $text = img_object($langs->trans('Product'), 'product'); + } + if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { + if ($reg[1] == 'DEPOSIT') { + $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); + } elseif ($reg[1] == 'CREDIT_NOTE') { + $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); + } else { + $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); + } + } + print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); + + // Show range + print_date_range($fields['ddate_start'], $fields['ddate_end']); + } + print '</td>'; + + // Total HT + if ($modetax != 1) { + print '<td class="nowrap right">'; + print price($fields['totalht']); + if (price2num($fields['ftotal_ttc'])) { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print '</td>'; + } + + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) { + print '<td class="nowrap right">'; + //print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc']; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) { + $payment_static->id = $fields['payment_id']; + print $payment_static->getNomUrl(2); + } + if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) { + print $langs->trans("NA"); + } else { + if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + print price(price2num($fields['payment_amount'], 'MT')); + if (isset($fields['payment_amount'])) { + print ' ('.round($ratiopaymentinvoice * 100, 2).'%)'; + } + } + print '</td>'; + } + + // Total collected + print '<td class="nowrap right">'; + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + print price(price2num($temp_ht, 'MT'), 1); + print '</td>'; + + // VAT + print '<td class="nowrap right">'; + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + print price(price2num($temp_vat, 'MT'), 1); + //print price($fields['vat']); + print '</td>'; + print '</tr>'; + + $subtot_coll_total_ht += $temp_ht; + $subtot_coll_vat += $temp_vat; + $x_coll_sum += $temp_vat; + } + } + // Total customers for this vat rate + print '<tr class="liste_total">'; + print '<td colspan="4"></td>'; + print '<td class="right">'.$langs->trans("Total").':</td>'; + if ($modetax != 1) { + print '<td class="nowrap right"> </td>'; + print '<td class="right"> </td>'; + } + print '<td class="right">'.price(price2num($subtot_coll_total_ht, 'MT')).'</td>'; + print '<td class="nowrap right">'.price(price2num($subtot_coll_vat, 'MT')).'</td>'; + print '</tr>'; + } + } + + if (count($x_coll) == 0) // Show a total ine if nothing shown + { + print '<tr class="liste_total">'; + print '<td colspan="4"></td>'; + print '<td class="right">'.$langs->trans("Total").':</td>'; + if ($modetax != 1) { + print '<td class="nowrap right"> </td>'; + print '<td class="right"> </td>'; + } + print '<td class="right">'.price(price2num(0, 'MT')).'</td>'; + print '<td class="nowrap right">'.price(price2num(0, 'MT')).'</td>'; + print '</tr>'; + } + + // Blank line + print '<tr><td colspan="'.($span + 1).'"> </td></tr>'; + + // Print table headers for this quadri - expenses now + print '<tr class="liste_titre liste_titre_topborder">'; + print '<td class="left">'.$elementsup.'</td>'; + print '<td class="left">'.$langs->trans("DateInvoice").'</td>'; + if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td class="left">'.$langs->trans("DatePayment").'</td>'; + else print '<td></td>'; + print '<td class="left">'.$namesup.'</td>'; + print '<td class="left">'.$productsup.'</td>'; + if ($modetax != 1) { + print '<td class="right">'.$amountsup.'</td>'; + print '<td class="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>'; + } + print '<td class="right">'.$langs->trans("AmountHTVATRealPaid").'</td>'; + print '<td class="right">'.$vatsup.'</td>'; + print '</tr>'."\n"; + + foreach (array_keys($x_paye) as $thirdparty_id) + { + $subtot_paye_total_ht = 0; + $subtot_paye_vat = 0; + + if ($min == 0 || ($min > 0 && $x_both[$thirdparty_id]['paye']['totalht'] > $min)) { + if (is_array($x_both[$thirdparty_id]['paye']['detail'])) { + print "<tr>"; + print '<td class="tax_rate">'; + if (is_numeric($thirdparty_id)) { + $company_static->fetch($thirdparty_id); + print $langs->trans("ThirdParty").': '.$company_static->getNomUrl(1); + } else { + $tmpid = preg_replace('/userid_/', '', $thirdparty_id); + $user_static->fetch($tmpid); + print $langs->trans("User").': '.$user_static->getNomUrl(1); + } + print '<td colspan="'.($span + 1).'"></td>'; + print '</tr>'."\n"; + + foreach ($x_both[$thirdparty_id]['paye']['detail'] as $index => $fields) { + // Define type + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($fields['ddate_start'])) { + $type = 1; + } + if (!empty($fields['ddate_end'])) { + $type = 1; + } + + + print '<tr class="oddeven">'; + + // Ref + print '<td class="nowrap left">'.$fields['link'].'</td>'; + + // Invoice date + print '<td class="left">'.dol_print_date($fields['datef'], 'day').'</td>'; + + // Payment date + if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') { + print '<td class="left">'.dol_print_date($fields['datep'], 'day').'</td>'; + } else { + print '<td></td>'; + } + + // Company name + print '<td class="left">'.$fields['company_link'].'</td>'; + + // Description + print '<td class="left">'; + if ($fields['pid']) { + $product_static->id = $fields['pid']; + $product_static->ref = $fields['pref']; + $product_static->type = $fields['dtype']; // We force with the type of line to have type how line is registered + print $product_static->getNomUrl(1); + if (dol_string_nohtmltag($fields['descr'])) { + print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); + } + } else { + if ($type) { + $text = img_object($langs->trans('Service'), 'service'); + } else { + $text = img_object($langs->trans('Product'), 'product'); + } + if (preg_match('/^\((.*)\)$/', $fields['descr'], $reg)) { + if ($reg[1] == 'DEPOSIT') { + $fields['descr'] = $langs->transnoentitiesnoconv('Deposit'); + } elseif ($reg[1] == 'CREDIT_NOTE') { + $fields['descr'] = $langs->transnoentitiesnoconv('CreditNote'); + } else { + $fields['descr'] = $langs->transnoentitiesnoconv($reg[1]); + } + } + print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); + + // Show range + print_date_range($fields['ddate_start'], $fields['ddate_end']); + } + print '</td>'; + + // Total HT + if ($modetax != 1) { + print '<td class="nowrap right">'; + print price($fields['totalht']); + if (price2num($fields['ftotal_ttc'])) { + //print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - "; + $ratiolineinvoice = ($fields['dtotal_ttc'] / $fields['ftotal_ttc']); + //print ' ('.round($ratiolineinvoice*100,2).'%)'; + } + print '</td>'; + } + + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) + { + print '<td class="nowrap right">'; + if ($fields['payment_amount'] && $fields['ftotal_ttc']) + { + $paymentfourn_static->id = $fields['payment_id']; + print $paymentfourn_static->getNomUrl(2); + } + + if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) + { + print $langs->trans("NA"); + } + else + { + if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + print price(price2num($fields['payment_amount'], 'MT')); + if (isset($fields['payment_amount'])) { + print ' ('.round($ratiopaymentinvoice * 100, 2).'%)'; + } + } + print '</td>'; + } + + // VAT paid + print '<td class="nowrap right">'; + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + print price(price2num($temp_ht, 'MT'), 1); + print '</td>'; + + // VAT + print '<td class="nowrap right">'; + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + print price(price2num($temp_vat, 'MT'), 1); + //print price($fields['vat']); + print '</td>'; + print '</tr>'; + + $subtot_paye_total_ht += $temp_ht; + $subtot_paye_vat += $temp_vat; + $x_paye_sum += $temp_vat; + } + } + // Total suppliers for this vat rate + print '<tr class="liste_total">'; + print '<td colspan="4"></td>'; + print '<td class="right">'.$langs->trans("Total").':</td>'; + if ($modetax != 1) { + print '<td class="nowrap right"> </td>'; + print '<td class="right"> </td>'; + } + print '<td class="right">'.price(price2num($subtot_paye_total_ht, 'MT')).'</td>'; + print '<td class="nowrap right">'.price(price2num($subtot_paye_vat, 'MT')).'</td>'; + print '</tr>'; + } + } + + if (count($x_paye) == 0) { // Show a total line if nothing shown + print '<tr class="liste_total">'; + print '<td colspan="4"></td>'; + print '<td class="right">'.$langs->trans("Total").':</td>'; + if ($modetax != 1) { + print '<td class="nowrap right"> </td>'; + print '<td class="right"> </td>'; + } + print '<td class="right">'.price(price2num(0, 'MT')).'</td>'; + print '<td class="nowrap right">'.price(price2num(0, 'MT')).'</td>'; + print '</tr>'; + } + + print '</table>'; + + // Total to pay + print '<br><br>'; + print '<table class="noborder centpercent">'; + $diff = $x_coll_sum - $x_paye_sum; + print '<tr class="liste_total">'; + print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').'</td>'; + print '<td class="liste_total nowrap right"><b>'.price(price2num($diff, 'MT'))."</b></td>\n"; + print "</tr>\n"; + + $i++; } print '</table>'; -print '</div>'; + llxFooter(); --- /tmp/dsg/dolibarr/htdocs/compta/tva/github_document.php +++ /tmp/dsg/dolibarr/htdocs/compta/tva/client_document.php @@ -36,8 +36,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; if (!empty($conf->projet->enabled)) { - require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; - require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } // Load translation files required by the page @@ -58,7 +58,7 @@ $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { - $page = 0; + $page = 0; } $offset = $limit * $page; $pageprev = $page - 1; @@ -82,10 +82,10 @@ if ($action == 'setlib' && $user->rights->tax->charges->creer) { - $object->fetch($id); - $result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', '', 'text', '', $user, 'TAX_MODIFY'); - if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); + $object->fetch($id); + $result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', '', 'text', '', $user, 'TAX_MODIFY'); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); } @@ -104,9 +104,9 @@ { $alreadypayed = $object->getSommePaiement(); - $head = vat_prepare_head($object); + $head = vat_prepare_head($object); - print dol_get_fiche_head($head, 'documents', $langs->trans("VATPayment"), -1, 'payment'); + dol_fiche_head($head, 'documents', $langs->trans("VATPayment"), -1, 'bill'); $morehtmlref = '<div class="refidno">'; // Label of social contribution @@ -123,33 +123,35 @@ print '<div class="fichecenter">'; print '<div class="underbanner clearboth"></div>'; - // Build file list - $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); - $totalsize = 0; - foreach ($filearray as $key => $file) - { - $totalsize += $file['size']; - } + // Build file list + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); + $totalsize = 0; + foreach ($filearray as $key => $file) + { + $totalsize += $file['size']; + } - print '<table class="border tableforfield centpercent">'; + print '<table class="border tableforfield centpercent">'; - print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>'; - print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>'; - print '</table>'; + print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>'; + print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>'; + print '</table>'; - print '</div>'; + print '</div>'; - print '<div class="clearboth"></div>'; + print '<div class="clearboth"></div>'; - print dol_get_fiche_end(); + dol_fiche_end(); - $permission = $user->rights->tax->charges->creer; - $permtoedit = $user->rights->fournisseur->facture->creer; - $param = '&id='.$object->id; - include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; -} else { - print $langs->trans("ErrorUnknown"); + $permission = $user->rights->tax->charges->creer; + $permtoedit = $user->rights->fournisseur->facture->creer; + $param = '&id='.$object->id; + include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; +} +else +{ + print $langs->trans("ErrorUnknown"); } --- /tmp/dsg/dolibarr/htdocs/compta/tva/github_index.php +++ /tmp/dsg/dolibarr/htdocs/compta/tva/client_index.php @@ -57,11 +57,14 @@ $q = GETPOST("q", "int"); if (empty($q)) { - if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } else { + if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } + else + { if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { // quaterly vat, we take last past complete quarter $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm'); $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1; - } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat + } + elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) { if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year $year_start--; @@ -73,12 +76,15 @@ } $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false); $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1; - } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month + } + elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm'); $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1; } } - } else { + } + else + { if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); } if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); } if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); } @@ -108,100 +114,103 @@ */ function pt($db, $sql, $date) { - global $conf, $bc, $langs; - - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - $i = 0; - $total = 0; - print '<table class="noborder centpercent">'; - - print '<tr class="liste_titre">'; - print '<td class="nowrap">'.$date.'</td>'; - print '<td class="right">'.$langs->trans("ClaimedForThisPeriod").'</td>'; - print '<td class="right">'.$langs->trans("PaidDuringThisPeriod").'</td>'; - print "</tr>\n"; - - $totalclaimed = 0; - $totalpaid = 0; - $amountclaimed = 0; - $amountpaid = 0; - $previousmonth = ''; - $previousmode = ''; - $mode = ''; - - while ($i < $num) { - $obj = $db->fetch_object($result); - $mode = $obj->mode; - - //print $obj->dm.' '.$obj->mode.' '.$previousmonth.' '.$previousmode; - if ($obj->mode == 'claimed' && !empty($previousmode)) - { - print '<tr class="oddeven">'; - print '<td class="nowrap">'.$previousmonth."</td>\n"; - print '<td class="nowrap right">'.price($amountclaimed)."</td>\n"; - print '<td class="nowrap right">'.price($amountpaid)."</td>\n"; - print "</tr>\n"; - - $amountclaimed = 0; - $amountpaid = 0; - } - - if ($obj->mode == 'claimed') - { - $amountclaimed = $obj->mm; - $totalclaimed = $totalclaimed + $amountclaimed; - } - if ($obj->mode == 'paid') - { - $amountpaid = $obj->mm; - $totalpaid = $totalpaid + $amountpaid; - } - - if ($obj->mode == 'paid') - { - print '<tr class="oddeven">'; - print '<td class="nowrap">'.$obj->dm."</td>\n"; - print '<td class="nowrap right">'.price($amountclaimed)."</td>\n"; - print '<td class="nowrap right">'.price($amountpaid)."</td>\n"; - print "</tr>\n"; - $amountclaimed = 0; - $amountpaid = 0; - $previousmode = ''; - $previousmonth = ''; - } else { - $previousmode = $obj->mode; - $previousmonth = $obj->dm; - } - - $i++; - } - - if ($mode == 'claimed' && !empty($previousmode)) - { - print '<tr class="oddeven">'; - print '<td class="nowrap">'.$previousmonth."</td>\n"; - print '<td class="nowrap right">'.price($amountclaimed)."</td>\n"; - print '<td class="nowrap right">'.price($amountpaid)."</td>\n"; - print "</tr>\n"; - - $amountclaimed = 0; - $amountpaid = 0; - } - - print '<tr class="liste_total">'; - print '<td class="right">'.$langs->trans("Total").'</td>'; - print '<td class="nowrap right">'.price($totalclaimed).'</td>'; - print '<td class="nowrap right">'.price($totalpaid).'</td>'; - print "</tr>"; - - print "</table>"; - - $db->free($result); - } else { - dol_print_error($db); - } + global $conf, $bc, $langs; + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; + $total = 0; + print '<table class="noborder centpercent">'; + + print '<tr class="liste_titre">'; + print '<td class="nowrap">'.$date.'</td>'; + print '<td class="right">'.$langs->trans("ClaimedForThisPeriod").'</td>'; + print '<td class="right">'.$langs->trans("PaidDuringThisPeriod").'</td>'; + print "</tr>\n"; + + $totalclaimed = 0; + $totalpaid = 0; + $amountclaimed = 0; + $amountpaid = 0; + $previousmonth = ''; + $previousmode = ''; + $mode = ''; + + while ($i < $num) { + $obj = $db->fetch_object($result); + $mode = $obj->mode; + + //print $obj->dm.' '.$obj->mode.' '.$previousmonth.' '.$previousmode; + if ($obj->mode == 'claimed' && !empty($previousmode)) + { + print '<tr class="oddeven">'; + print '<td class="nowrap">'.$previousmonth."</td>\n"; + print '<td class="nowrap right">'.price($amountclaimed)."</td>\n"; + print '<td class="nowrap right">'.price($amountpaid)."</td>\n"; + print "</tr>\n"; + + $amountclaimed = 0; + $amountpaid = 0; + } + + if ($obj->mode == 'claimed') + { + $amountclaimed = $obj->mm; + $totalclaimed = $totalclaimed + $amountclaimed; + } + if ($obj->mode == 'paid') + { + $amountpaid = $obj->mm; + $totalpaid = $totalpaid + $amountpaid; + } + + if ($obj->mode == 'paid') + { + print '<tr class="oddeven">'; + print '<td class="nowrap">'.$obj->dm."</td>\n"; + print '<td class="nowrap right">'.price($amountclaimed)."</td>\n"; + print '<td class="nowrap right">'.price($amountpaid)."</td>\n"; + print "</tr>\n"; + $amountclaimed = 0; + $amountpaid = 0; + $previousmode = ''; + $previousmonth = ''; + } + else + { + $previousmode = $obj->mode; + $previousmonth = $obj->dm; + } + + $i++; + } + + if ($mode == 'claimed' && !empty($previousmode)) + { + print '<tr class="oddeven">'; + print '<td class="nowrap">'.$previousmonth."</td>\n"; + print '<td class="nowrap right">'.price($amountclaimed)."</td>\n"; + print '<td class="nowrap right">'.price($amountpaid)."</td>\n"; + print "</tr>\n"; + + $amountclaimed = 0; + $amountpaid = 0; + } + + print '<tr class="liste_total">'; + print '<td class="right">'.$langs->trans("Total").'</td>'; + print '<td class="nowrap right">'.price($totalclaimed).'</td>'; + print '<td class="nowrap right">'.price($totalpaid).'</td>'; + print "</tr>"; + + print "</table>"; + + $db->free($result); + } + else { + dol_print_error($db); + } } @@ -220,12 +229,12 @@ $description = $fsearch; // Show report header -$name = $langs->trans("VATReportByMonth"); +$name = $langs->trans("ReportByMonth"); $calcmode = ''; if ($modetax == 0) $calcmode = $langs->trans('OptionVATDefault'); if ($modetax == 1) $calcmode = $langs->trans('OptionVATDebitOption'); if ($modetax == 2) $calcmode = $langs->trans('OptionPaymentForProductAndServices'); -$calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')</span>'; +$calcmode .= '<br>('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')'; $description .= $langs->trans("VATSummary").'<br>'; if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') $description .= $langs->trans("RulesVATDueProducts"); @@ -362,7 +371,9 @@ 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], //'link' =>$expensereport->getNomUrl(1) ); - } else { + } + else + { //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id]; //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id]; //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id]; @@ -392,144 +403,144 @@ } //now we have an array (x_both) indexed by rates for coll and paye - $action = "tva"; - $object = array(&$x_coll, &$x_paye, &$x_both); - $parameters["mode"] = $modetax; - $parameters["year"] = $y; - $parameters["month"] = $m; - $parameters["type"] = 'vat'; - - // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array - $hookmanager->initHooks(array('externalbalance')); - $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks - - if (!is_array($x_coll) && $coll_listbuy == -1) - { - $langs->load("errors"); - print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>'; - break; - } - if (!is_array($x_paye) && $coll_listbuy == -2) - { - print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'; - break; - } - - - print '<tr class="oddeven">'; - print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/tva/quadri_detail.php?leftmenu=tax_vat&month='.$m.'&year='.$y.'">'.dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y").'</a></td>'; - - $x_coll_sum = 0; - foreach (array_keys($x_coll) as $rate) - { - $subtot_coll_total_ht = 0; - $subtot_coll_vat = 0; - - foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) - { - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) - { - // Define type - // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. - $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - if (!empty($fields['ddate_start'])) { - $type = 1; - } - if (!empty($fields['ddate_end'])) { - $type = 1; - } - - if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) - { - //print $langs->trans("NA"); - } else { - if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - } - } - //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice); - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - $subtot_coll_total_ht += $temp_ht; - $subtot_coll_vat += $temp_vat; - $x_coll_sum += $temp_vat; - } - } - print '<td class="nowrap right">'.price(price2num($x_coll_sum, 'MT')).'</td>'; - - $x_paye_sum = 0; - foreach (array_keys($x_paye) as $rate) - { - $subtot_paye_total_ht = 0; - $subtot_paye_vat = 0; - - foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) - { - // Payment - $ratiopaymentinvoice = 1; - if ($modetax != 1) - { - // Define type - // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. - $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - if (!empty($fields['ddate_start'])) { - $type = 1; - } - if (!empty($fields['ddate_end'])) { - $type = 1; - } - - if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') - || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) - { - //print $langs->trans("NA"); - } else { - if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { - $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); - } - } - } - //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice); - $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; - $temp_vat = $fields['vat'] * $ratiopaymentinvoice; - $subtot_paye_total_ht += $temp_ht; - $subtot_paye_vat += $temp_vat; - $x_paye_sum += $temp_vat; - } - } - print '<td class="nowrap right">'.price(price2num($x_paye_sum, 'MT')).'</td>'; - - $subtotalcoll = $subtotalcoll + $x_coll_sum; - $subtotalpaye = $subtotalpaye + $x_paye_sum; - - $diff = $x_coll_sum - $x_paye_sum; - $total = $total + $diff; - $subtotal = price2num($subtotal + $diff, 'MT'); - - print '<td class="nowrap right">'.price(price2num($diff, 'MT')).'</td>'."\n"; - print "<td> </td>\n"; - print "</tr>\n"; - - $i++; $m++; - if ($i > 2) - { - print '<tr class="liste_total">'; - print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>'; - print '<td class="nowrap right">'.price(price2num($subtotalcoll, 'MT')).'</td>'; - print '<td class="nowrap right">'.price(price2num($subtotalpaye, 'MT')).'</td>'; - print '<td class="nowrap right">'.price(price2num($subtotal, 'MT')).'</td>'; - print '<td> </td></tr>'; - $i = 0; - $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0; - } + $action = "tva"; + $object = array(&$x_coll, &$x_paye, &$x_both); + $parameters["mode"] = $modetax; + $parameters["year"] = $y; + $parameters["month"] = $m; + $parameters["type"] = 'vat'; + + // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array + $hookmanager->initHooks(array('externalbalance')); + $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks + + if (!is_array($x_coll) && $coll_listbuy == -1) + { + $langs->load("errors"); + print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>'; + break; + } + if (!is_array($x_paye) && $coll_listbuy == -2) + { + print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'; + break; + } + + + print '<tr class="oddeven">'; + print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/compta/tva/quadri_detail.php?leftmenu=tax_vat&month='.$m.'&year='.$y.'">'.dol_print_date(dol_mktime(0, 0, 0, $m, 1, $y), "%b %Y").'</a></td>'; + + $x_coll_sum = 0; + foreach (array_keys($x_coll) as $rate) + { + $subtot_coll_total_ht = 0; + $subtot_coll_vat = 0; + + foreach ($x_both[$rate]['coll']['detail'] as $index => $fields) + { + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) + { + // Define type + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($fields['ddate_start'])) { + $type = 1; + } + if (!empty($fields['ddate_end'])) { + $type = 1; + } + + if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) + { + //print $langs->trans("NA"); + } else { + if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + } + } + //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice); + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + $subtot_coll_total_ht += $temp_ht; + $subtot_coll_vat += $temp_vat; + $x_coll_sum += $temp_vat; + } + } + print '<td class="nowrap right">'.price(price2num($x_coll_sum, 'MT')).'</td>'; + + $x_paye_sum = 0; + foreach (array_keys($x_paye) as $rate) + { + $subtot_paye_total_ht = 0; + $subtot_paye_vat = 0; + + foreach ($x_both[$rate]['paye']['detail'] as $index => $fields) + { + // Payment + $ratiopaymentinvoice = 1; + if ($modetax != 1) + { + // Define type + // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown. + $type = (isset($fields['dtype']) ? $fields['dtype'] : $fields['ptype']); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($fields['ddate_start'])) { + $type = 1; + } + if (!empty($fields['ddate_end'])) { + $type = 1; + } + + if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') + || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')) + { + //print $langs->trans("NA"); + } else { + if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) { + $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); + } + } + } + //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice); + $temp_ht = $fields['totalht'] * $ratiopaymentinvoice; + $temp_vat = $fields['vat'] * $ratiopaymentinvoice; + $subtot_paye_total_ht += $temp_ht; + $subtot_paye_vat += $temp_vat; + $x_paye_sum += $temp_vat; + } + } + print '<td class="nowrap right">'.price(price2num($x_paye_sum, 'MT')).'</td>'; + + $subtotalcoll = $subtotalcoll + $x_coll_sum; + $subtotalpaye = $subtotalpaye + $x_paye_sum; + + $diff = $x_coll_sum - $x_paye_sum; + $total = $total + $diff; + $subtotal = price2num($subtotal + $diff, 'MT'); + + print '<td class="nowrap right">'.price(price2num($diff, 'MT')).'</td>'."\n"; + print "<td> </td>\n"; + print "</tr>\n"; + + $i++; $m++; + if ($i > 2) + { + print '<tr class="liste_total">'; + print '<td class="right"><a href="quadri_detail.php?leftmenu=tax_vat&q='.round($m / 3).'&year='.$y.'">'.$langs->trans("SubTotal").'</a>:</td>'; + print '<td class="nowrap right">'.price(price2num($subtotalcoll, 'MT')).'</td>'; + print '<td class="nowrap right">'.price(price2num($subtotalpaye, 'MT')).'</td>'; + print '<td class="nowrap right">'.price(price2num($subtotal, 'MT')).'</td>'; + print '<td> </td></tr>'; + $i = 0; + $subtotalcoll = 0; $subtotalpaye = 0; $subtotal = 0; + } } print '<tr class="liste_total"><td class="right" colspan="3">'.$langs->trans("TotalToPay").':</td><td class="nowrap right">'.price(price2num($total, 'MT')).'</td>'; print "<td> </td>\n"; @@ -543,7 +554,7 @@ /* - * Paid + * Payed */ print load_fiche_titre($langs->trans("VATPaid"), '', ''); @@ -578,37 +589,37 @@ * Recap */ - print load_fiche_titre($langs->trans("VATBalance"), '', ''); // need to add translation - - $sql1 = "SELECT SUM(amount) as mm"; - $sql1 .= " FROM ".MAIN_DB_PREFIX."tva as f"; - $sql1 .= " WHERE f.entity = ".$conf->entity; - $sql1 .= " AND f.datev >= '".$db->idate($date_start)."'"; - $sql1 .= " AND f.datev <= '".$db->idate($date_end)."'"; - - $result = $db->query($sql1); - if ($result) { - $obj = $db->fetch_object($result); - print '<table class="noborder centpercent">'; - - print "<tr>"; - print '<td class="right">'.$langs->trans("VATDue").'</td>'; - print '<td class="nowrap right">'.price(price2num($total, 'MT')).'</td>'; - print "</tr>\n"; - - print "<tr>"; - print '<td class="right">'.$langs->trans("VATPaid").'</td>'; - print '<td class="nowrap right">'.price(price2num($obj->mm, 'MT'))."</td>\n"; - print "</tr>\n"; - - $restopay = $total - $obj->mm; - print "<tr>"; - print '<td class="right">'.$langs->trans("RemainToPay").'</td>'; - print '<td class="nowrap right">'.price(price2num($restopay, 'MT')).'</td>'; - print "</tr>\n"; - - print '</table>'; - } + print load_fiche_titre($langs->trans("VATBalance"), '', ''); // need to add translation + + $sql1 = "SELECT SUM(amount) as mm"; + $sql1 .= " FROM ".MAIN_DB_PREFIX."tva as f"; + $sql1 .= " WHERE f.entity = ".$conf->entity; + $sql1 .= " AND f.datev >= '".$db->idate($date_start)."'"; + $sql1 .= " AND f.datev <= '".$db->idate($date_end)."'"; + + $result = $db->query($sql1); + if ($result) { + $obj = $db->fetch_object($result); + print '<table class="noborder centpercent">'; + + print "<tr>"; + print '<td class="right">'.$langs->trans("VATDue").'</td>'; + print '<td class="nowrap right">'.price(price2num($total, 'MT')).'</td>'; + print "</tr>\n"; + + print "<tr>"; + print '<td class="right">'.$langs->trans("VATPaid").'</td>'; + print '<td class="nowrap right">'.price(price2num($obj->mm, 'MT'))."</td>\n"; + print "</tr>\n"; + + $restopay = $total - $obj->mm; + print "<tr>"; + print '<td class="right">'.$langs->trans("RemainToPay").'</td>'; + print '<td class="nowrap right">'.price(price2num($restopay, 'MT')).'</td>'; + print "</tr>\n"; + + print '</table>'; + } } print '</div></div>'; --- /tmp/dsg/dolibarr/htdocs/compta/tva/github_info.php +++ /tmp/dsg/dolibarr/htdocs/compta/tva/client_info.php @@ -68,7 +68,7 @@ $head = vat_prepare_head($object); -print dol_get_fiche_head($head, 'info', $langs->trans("VATPayment"), -1, 'payment'); +dol_fiche_head($head, 'info', $langs->trans("VATPayment"), -1, 'payment'); $morehtmlref = '<div class="refidno">'; // Label of social contribution @@ -89,7 +89,7 @@ print '</div>'; -print dol_get_fiche_end(); +dol_fiche_end(); llxFooter(); --- /tmp/dsg/dolibarr/htdocs/compta/tva/github_list.php +++ /tmp/dsg/dolibarr/htdocs/compta/tva/client_list.php @@ -1,9 +1,8 @@ <?php -/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> - * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net> - * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com> - * Copyright (C) 2011-2019 Alexandre Spangaro <aspangaro@open-dsi.fr> - * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com> +/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> + * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com> + * Copyright (C) 2011-2019 Alexandre Spangaro <aspangaro@open-dsi.fr> * * 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 @@ -20,18 +19,12 @@ */ /** - * \file htdocs/compta/tva/list.php - * \ingroup tax - * \brief List of VAT payments + * \file htdocs/compta/tva/list.php + * \ingroup tax + * \brief List of VAT payments */ require '../../main.inc.php'; - -// Security check -$socid = GETPOST('socid', 'int'); -if ($user->socid) $socid = $user->socid; -$result = restrictedArea($user, 'tax', '', '', 'charges'); - require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; @@ -41,404 +34,268 @@ // Load translation files required by the page $langs->loadLangs(array('compta', 'bills')); -$action = GETPOST('action', 'alpha'); -$massaction = GETPOST('massaction', 'alpha'); -$confirm = GETPOST('confirm', 'alpha'); -$optioncss = GETPOST('optioncss', 'alpha'); -$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'salestaxeslist'; - -$search_ref = GETPOST('search_ref', 'alpha'); +// Security check +$socid = GETPOST('socid', 'int'); +if ($user->socid) $socid = $user->socid; +$result = restrictedArea($user, 'tax', '', '', 'charges'); + +$search_ref = GETPOST('search_ref', 'int'); $search_label = GETPOST('search_label', 'alpha'); +$search_account = GETPOST('search_account', 'int'); $search_dateend_start = dol_mktime(0, 0, 0, GETPOST('search_dateend_startmonth', 'int'), GETPOST('search_dateend_startday', 'int'), GETPOST('search_dateend_startyear', 'int')); $search_dateend_end = dol_mktime(23, 59, 59, GETPOST('search_dateend_endmonth', 'int'), GETPOST('search_dateend_endday', 'int'), GETPOST('search_dateend_endyear', 'int')); $search_datepayment_start = dol_mktime(0, 0, 0, GETPOST('search_datepayment_startmonth', 'int'), GETPOST('search_datepayment_startday', 'int'), GETPOST('search_datepayment_startyear', 'int')); $search_datepayment_end = dol_mktime(23, 59, 59, GETPOST('search_datepayment_endmonth', 'int'), GETPOST('search_datepayment_endday', 'int'), GETPOST('search_datepayment_endyear', 'int')); -$search_type = GETPOST('search_type', 'int'); -$search_cheque = GETPOST('search_cheque', 'alpha'); -$search_account = GETPOST('search_account', 'int'); -$search_amount = GETPOST('search_amount', 'alpha'); - -$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'alpha'); -$sortorder = GETPOST('sortorder', 'alpha'); -$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST('page', 'int'); - -if (empty($page) || $page == -1) $page = 0; // If $page is not defined, or '' or -1 +$search_amount = GETPOST('search_amount', 'alpha'); +$month = GETPOST("month", "int"); +$year = GETPOST("year", "int"); + +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; - -if (!$sortfield) $sortfield = 't.datev'; -if (!$sortorder) $sortorder = 'DESC'; - -$arrayfields = array( - 't.rowid' =>array('checked'=>1, 'position'=>10, 'label'=>"Ref",), - 't.label' =>array('checked'=>1, 'position'=>20, 'label'=>"Label"), - 't.datev' =>array('checked'=>1, 'position'=>30, 'label'=>"PeriodEndDate"), - 't.datep' =>array('checked'=>1, 'position'=>40, 'label'=>"DatePayment"), - 't.fk_typepayment' =>array('checked'=>1, 'position'=>50, 'label'=>"Type"), - 't.num_payment' =>array('checked'=>1, 'position'=>60, 'label'=>"Numero", 'tooltip'=>"ChequeOrTransferNumber"), - 'transaction' =>array('checked'=>1, 'position'=>70, 'label'=>"BankTransactionLine", 'enabled'=>(!empty($conf->banque->enabled))), - 'ba.label' =>array('checked'=>1, 'position'=>80, 'label'=>"Account", 'enable'=>(!empty($conf->banque->enabled))), - 't.amount' =>array('checked'=>1, 'position'=>90, 'label'=>"PayedByThisPayment"), -); -$arrayfields = dol_sort_array($arrayfields, 'position'); - -// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context -$hookmanager->initHooks(array('salestaxeslist')); -$object = new Tva($db); - - -/* - * Actions - */ - -$parameters = array('socid'=>$socid); -$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - - -if (empty($reshook)) { - include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers +if (!$sortfield) $sortfield = "t.datev"; +if (!$sortorder) $sortorder = "DESC"; + +$filtre = $_GET["filtre"]; + +if (empty($_REQUEST['typeid'])) +{ + $newfiltre = str_replace('filtre=', '', $filtre); + $filterarray = explode('-', $newfiltre); + foreach ($filterarray as $val) { - $search_ref = ''; - $search_label = ''; - $search_dateend_start = ''; - $search_dateend_end = ''; - $search_datepayment_start = ''; - $search_datepayment_end = ''; - $search_type = ''; - $search_cheque = ''; - $search_account = ''; - $search_amount = ''; + $part = explode(':', $val); + if ($part[0] == 't.fk_typepayment') $typeid = $part[1]; } +} +else +{ + $typeid = $_REQUEST['typeid']; +} + +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers +{ + $search_ref = ""; + $search_label = ""; + $search_dateend_start = ''; + $search_dateend_end = ''; + $search_datepayment_start = ''; + $search_datepayment_end = ''; + $search_account = ''; + $search_amount = ""; + $year = ""; + $month = ""; + $typeid = ""; } /* * View */ + +llxHeader('', $langs->trans("VATPayments")); $form = new Form($db); $formother = new FormOther($db); $tva_static = new Tva($db); $bankstatic = new Account($db); -$accountingjournal = new AccountingJournal($db); -$bankline = new AccountLine($db); - -llxHeader('', $langs->trans("VATPayments")); - -$sql = 'SELECT t.rowid, t.amount, t.label, t.datev, t.datep, t.fk_typepayment as type, t.num_payment, t.fk_bank'; -$sql .= ', ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel'; -$sql .= ', pst.code as payment_code'; -$sql .= ' FROM '.MAIN_DB_PREFIX.'tva as t'; -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pst ON t.fk_typepayment = pst.id'; -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; -$sql .= ' WHERE t.entity IN ('.getEntity($object->element).')'; - -if (!empty($search_ref)) $sql .= natural_search('t.rowid', $search_ref); -if (!empty($search_label)) $sql .= natural_search('t.label', $search_label); -if (!empty($search_dateend_start)) $sql .= ' AND t.datev >= "'.$db->idate($search_dateend_start).'"'; -if (!empty($search_dateend_end)) $sql .= ' AND t.datev <= "'.$db->idate($search_dateend_end).'"'; -if (!empty($search_datepayment_start)) $sql .= ' AND t.datep >= "'.$db->idate($search_datepayment_start).'"'; -if (!empty($search_datepayment_end)) $sql .= ' AND t.datep <= "'.$db->idate($search_datepayment_end).'"'; -if (!empty($search_type) && $search_type > 0) $sql .= ' AND t.fk_typepayment='.$search_type; -if (!empty($search_cheque)) $sql .= natural_search('t.num_payment', $search_cheque); -if (!empty($search_account) && $search_account > 0) $sql .= ' AND b.fk_account='.$search_account; -if (!empty($search_amount)) $sql .= natural_search('t.amount', price2num(trim($search_amount)), 1); - + +$sql = "SELECT t.rowid, t.amount, t.label, t.datev, t.datep, t.fk_typepayment as type, t.num_payment, t.fk_bank, pst.code as payment_code,"; +$sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel"; +$sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; +$sql .= " WHERE t.entity IN (".getEntity('tax').")"; +if ($search_ref) $sql .= natural_search("t.rowid", $search_ref); +if ($search_label) $sql .= natural_search("t.label", $search_label); +if ($search_account > 0) $sql .= " AND b.fk_account=".$search_account; +if ($search_amount) $sql .= natural_search("t.amount", price2num(trim($search_amount)), 1); +if ($search_dateend_start) $sql .= " AND t.datev >= '".$db->idate($search_dateend_start)."'"; +if ($search_dateend_end) $sql .= " AND t.datev <= '".$db->idate($search_dateend_end)."'"; +if ($search_datepayment_start) $sql .= " AND t.datep >= '".$db->idate($search_datepayment_start)."'"; +if ($search_datepayment_end) $sql .= " AND t.datep <= '".$db->idate($search_datepayment_end)."'"; +if ($filtre) { + $filtre = str_replace(":", "=", $filtre); + $sql .= " AND ".$filtre; +} +if ($typeid) { + $sql .= " AND t.fk_typepayment=".$typeid; +} $sql .= $db->order($sortfield, $sortorder); - -$nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); - - // if total resultset is smaller then paging size (filtering), goto and load page 0 - if (($page * $limit) > $nbtotalofrecords) { - $page = 0; - $offset = 0; - } -} - +$totalnboflines = 0; +$result = $db->query($sql); +if ($result) +{ + $totalnboflines = $db->num_rows($result); +} $sql .= $db->plimit($limit + 1, $offset); $result = $db->query($sql); -if (!$result) -{ - dol_print_error($db); - llxFooter(); - $db->close(); - exit; -} - -$num = $db->num_rows($result); - -$param = ''; -if (!empty($contextpage) && $contextpage != $_SERVER['PHP_SELF']) $param .= '&contextpage='.$contextpage; -if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; -if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); - -if (!empty($search_ref)) $param .= '&search_ref="'.$search_ref.'"'; -if (!empty($search_label)) $param .= '&search_label="'.$search_label.'"'; -if (!empty($search_dateend_start)) $param .= '&search_dateend_startyear='.GETPOST('search_dateend_startyear', 'int'); -if (!empty($search_dateend_start)) $param .= '&search_dateend_startmonth='.GETPOST('search_dateend_startmonth', 'int'); -if (!empty($search_dateend_start)) $param .= '&search_dateend_startday='.GETPOST('search_dateend_startday', 'int'); -if (!empty($search_dateend_end)) $param .= '&search_dateend_endyear='.GETPOST('search_dateend_endyear', 'int'); -if (!empty($search_dateend_end)) $param .= '&search_dateend_endmonth='.GETPOST('search_dateend_endmonth', 'int'); -if (!empty($search_dateend_end)) $param .= '&search_dateend_endday='.GETPOST('search_dateend_endday', 'int'); -if (!empty($search_datepayment_start)) $param .= '&search_datepayment_startyear='.GETPOST('search_datepayment_startyear', 'int'); -if (!empty($search_datepayment_start)) $param .= '&search_datepayment_startmonth='.GETPOST('search_datepayment_startmonth', 'int'); -if (!empty($search_datepayment_start)) $param .= '&search_datepayment_startday='.GETPOST('search_datepayment_startday', 'int'); -if (!empty($search_datepayment_end)) $param .= '&search_datepayment_endyear='.GETPOST('search_datepayment_endyear', 'int'); -if (!empty($search_datepayment_end)) $param .= '&search_datepayment_endmonth='.GETPOST('search_datepayment_endmonth', 'int'); -if (!empty($search_datepayment_end)) $param .= '&search_datepayment_endday='.GETPOST('search_datepayment_endday', 'int'); -if (!empty($search_type) && $search_type > 0) $param .= '&search_type='.$search_type; -if (!empty($search_cheque)) $param .= '&search_cheque="'.$search_cheque.'"'; -if (!empty($search_account) && $search_account > 0) $param .= '&search_account='.$search_account; -if (!empty($search_amount)) $param .= '&search_amount="'.$search_amount.'"'; - -print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; -if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; -print '<input type="hidden" name="token" value="'.newToken().'">'; -print '<input type="hidden" name="action" value="list">'; -print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; -print '<input type="hidden" name="sortfield" value="'.$sortfield.'">'; -print '<input type="hidden" name="sortorder" value="'.$sortorder.'">'; -print '<input type="hidden" name="contextpage" value="'.$contextpage.'">'; - -$url = DOL_URL_ROOT.'/compta/tva/card.php?action=create'; -if (!empty($socid)) $url .= '&socid='.$socid; -$newcardbutton = dolGetButtonTitle($langs->trans('NewVATPayment', ($ltt + 1)), '', 'fa fa-plus-circle', $url, '', $user->rights->tax->charges->creer); -print_barre_liste($langs->trans("VATPayments"), $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); - -$varpage = empty($contextpage) ? $_SERVER['PHP_SELF'] : $contextpage; -$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields -if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); - -print '<div class="div-table-responsive">'; -print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : '').'">'; - -print '<tr class="liste_titre_filter">'; - -// Filters: Lines (placeholder) -if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) { - print '<td class="liste_titre">'; - print '</td>'; -} - -// Filter: Ref -if (!empty($arrayfields['t.rowid']['checked'])) { - print '<td class="liste_titre">'; - print '<input type="text" class="flat" size="4" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">'; - print '</td>'; -} - -// Filter: Label -if (!empty($arrayfields['t.label']['checked'])) { - print '<td class="liste_titre">'; - print '<input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).'">'; - print '</td>'; -} - -// Filter: Date end period -if (!empty($arrayfields['t.datev']['checked'])) { +if ($result) +{ + $num = $db->num_rows($result); + $i = 0; + $total = 0; + + $param = ''; + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage; + if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; + if ($typeid) $param .= '&typeid='.$typeid; + + $newcardbutton = ''; + if ($user->rights->tax->charges->creer) + { + $newcardbutton .= dolGetButtonTitle($langs->trans('NewVATPayment', ($ltt + 1)), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/tva/card.php?action=create'); + } + + print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'; + if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; + print '<input type="hidden" name="token" value="'.newToken().'">'; + print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; + print '<input type="hidden" name="sortfield" value="'.$sortfield.'">'; + print '<input type="hidden" name="sortorder" value="'.$sortorder.'">'; + + print_barre_liste($langs->trans("VATPayments"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); + + print '<div class="div-table-responsive">'; + print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n"; + + print '<tr class="liste_titre_filter">'; + // Ref + print '<td class="liste_titre"><input type="text" class="flat" size="4" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>'; + // Label + print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>'; + // Date end period print '<td class="liste_titre center">'; print '<div class="nowrap">'; - print $form->selectDate($search_dateend_start ? $search_dateend_start : -1, 'search_dateend_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); + print $langs->trans('From').' '; + print $form->selectDate($search_dateend_start ? $search_dateend_start : -1, 'search_dateend_start', 0, 0, 1); print '</div>'; print '<div class="nowrap">'; - print $form->selectDate($search_dateend_end ? $search_dateend_end : -1, 'search_dateend_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); + print $langs->trans('to').' '; + print $form->selectDate($search_dateend_end ? $search_dateend_end : -1, 'search_dateend_end', 0, 0, 1); print '</div>'; - print '</td>'; -} - -// Filter: Date payment -if (!empty($arrayfields['t.datep']['checked'])) { + // Date payment print '<td class="liste_titre center">'; print '<div class="nowrap">'; - print $form->selectDate($search_datepayment_start ? $search_datepayment_start : -1, 'search_datepayment_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); + print $langs->trans('From').' '; + print $form->selectDate($search_datepayment_start ? $search_datepayment_start : -1, 'search_datepayment_start', 0, 0, 1); print '</div>'; print '<div class="nowrap">'; - print $form->selectDate($search_datepayment_end ? $search_datepayment_end : -1, 'search_datepayment_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); + print $langs->trans('to').' '; + print $form->selectDate($search_datepayment_end ? $search_datepayment_end : -1, 'search_datepayment_end', 0, 0, 1); print '</div>'; + // Type + print '<td class="liste_titre left">'; + $form->select_types_paiements($typeid, 'typeid', '', 0, 1, 1, 16); print '</td>'; -} - -// Filter: Type -if (!empty($arrayfields['t.fk_typepayment']['checked'])) { - print '<td class="liste_titre left">'; - $form->select_types_paiements($search_type, 'search_type', '', 0, 1, 1, 16); - print '</td>'; -} - -// Filter: Cheque number -if (!empty($arrayfields['t.num_payment']['checked'])) { - print '<td class="liste_titre left">'; - print '<input name="search_cheque" class="flat" type="text" size="8" value="'.$search_cheque.'">'; - print '</td>'; -} - -// Filter: Bank transaction number (placeholder) -if (!empty($arrayfields['transaction']['checked'])) { - print '<td class="liste_titre">'; - print '</td>'; -} - -// Filter: Bank account -if (!empty($arrayfields['ba.label']['checked'])) { - print '<td class="liste_titre">'; - $form->select_comptes($search_account, 'search_account', 0, '', 1); - print '</td>'; -} - -// Filter: Amount -if (!empty($arrayfields['t.amount']['checked'])) { - print '<td class="liste_titre right">'; - print '<input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'">'; - print '</td>'; -} - -// Fields from hook -$parameters = array('arrayfields'=>$arrayfields); -$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook -print $hookmanager->resPrint; - -// Filter: Buttons -print '<td class="liste_titre maxwidthsearch">'; -print $form->showFilterAndCheckAddButtons(0); -print '</td>'; - -print '</tr>'; - -print '<tr class="liste_titre">'; -if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['t.rowid']['checked'])) print_liste_field_titre($arrayfields['t.rowid']['label'], $_SERVER['PHP_SELF'], 't.rowid', '', $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['t.label']['checked'])) print_liste_field_titre($arrayfields['t.label']['label'], $_SERVER['PHP_SELF'], 't.label', '', $param, 'align="left"', $sortfield, $sortorder); -if (!empty($arrayfields['t.datev']['checked'])) print_liste_field_titre($arrayfields['t.datev']['label'], $_SERVER['PHP_SELF'], 't.datev', '', $param, 'align="center"', $sortfield, $sortorder); -if (!empty($arrayfields['t.datep']['checked'])) print_liste_field_titre($arrayfields['t.datep']['label'], $_SERVER['PHP_SELF'], 't.datep', '', $param, 'align="center"', $sortfield, $sortorder); -if (!empty($arrayfields['t.fk_typepayment']['checked'])) print_liste_field_titre($arrayfields['t.fk_typepayment']['label'], $_SERVER['PHP_SELF'], 't.fk_typepayment', '', $param, '', $sortfield, $sortorder, 'left '); -if (!empty($arrayfields['t.num_payment']['checked'])) print_liste_field_titre($arrayfields['t.num_payment']['label'], $_SERVER['PHP_SELF'], 't.num_payment', '', $param, '', $sortfield, $sortorder, '', $arrayfields['t.num_payment']['tooltip']); -if (!empty($arrayfields['transaction']['checked'])) print_liste_field_titre($arrayfields['transaction']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['ba.label']['checked'])) print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER['PHP_SELF'], 'ba.label', '', $param, '', $sortfield, $sortorder, 'left '); -if (!empty($arrayfields['t.amount']['checked'])) print_liste_field_titre($arrayfields['t.amount']['label'], $_SERVER['PHP_SELF'], 't.amount', '', $param, '', $sortfield, $sortorder, 'right '); - -// Hook fields -$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); -$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook -print $hookmanager->resPrint; - -print_liste_field_titre($selectedfields, $_SERVER['PHP_SELF'], '', '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); -print '</tr>'; - -$i = 0; -$totalarray = array(); -while ($i < min($num, $limit)) { - $obj = $db->fetch_object($result); - - $tva_static->id = $obj->rowid; - $tva_static->ref = $obj->rowid; - - print '<tr class="oddeven">'; - - // No - if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) { - print '<td>'.(($offset * $limit) + $i).'</td>'; - if (!$i) $totalarray['nbfield']++; - } - - // Ref - if (!empty($arrayfields['t.rowid']['checked'])) { - print '<td>'.$tva_static->getNomUrl(1).'</td>'; - if (!$i) $totalarray['nbfield']++; - } - - // Label - if (!empty($arrayfields['t.label']['checked'])) { - print '<td>'.dol_trunc($obj->label, 40).'</td>'; - if (!$i) $totalarray['nbfield']++; - } - - // Date end period - if (!empty($arrayfields['t.datev']['checked'])) { - print '<td class="center">'.dol_print_date($db->jdate($obj->datev), 'day').'</td>'; - if (!$i) $totalarray['nbfield']++; - } - - // Date payment - if (!empty($arrayfields['t.datep']['checked'])) { - print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day').'</td>'; - if (!$i) $totalarray['nbfield']++; - } - - // Type - if (!empty($arrayfields['t.fk_typepayment']['checked'])) - { - print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).'</td>'; - if (!$i) $totalarray['nbfield']++; - } - - // Cheque number - if (!empty($arrayfields['t.num_payment']['checked'])) { - print '<td>'.$obj->num_payment.'</td>'; - if (!$i) $totalarray['nbfield']++; - } - - // Bank transaction - if (!empty($arrayfields['transaction']['checked'])) { - $bankline->fetch($obj->fk_bank); - print '<td>'.$bankline->getNomUrl(1, 0).'</td>'; - if (!$i) $totalarray['nbfield']++; - } - // Account - if (!empty($arrayfields['ba.label']['checked'])) { - print '<td>'; - if ($obj->fk_bank > 0) { - $bankstatic->id = $obj->bid; - $bankstatic->ref = $obj->bref; - $bankstatic->number = $obj->bnumber; - $bankstatic->account_number = $obj->account_number; - - $accountingjournal->fetch($obj->fk_accountancy_journal); - $bankstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1); - - $bankstatic->label = $obj->blabel; - print $bankstatic->getNomUrl(1); + if (!empty($conf->banque->enabled)) + { + print '<td class="liste_titre">'; + $form->select_comptes($search_account, 'search_account', 0, '', 1); + print '</td>'; + } + // Amount + print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$search_amount.'"></td>'; + print '<td class="liste_titre maxwidthsearch">'; + $searchpicto = $form->showFilterAndCheckAddButtons(0); + print $searchpicto; + print '</td>'; + print "</tr>\n"; + + print '<tr class="liste_titre">'; + print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "t.rowid", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "t.label", "", $param, 'align="left"', $sortfield, $sortorder); + print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "t.datev", "", $param, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "t.datep", "", $param, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "type", "", $param, '', $sortfield, $sortorder, 'left '); + if (!empty($conf->banque->enabled)) print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "t.amount", "", $param, '', $sortfield, $sortorder, 'right '); + print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch '); + print "</tr>\n"; + + while ($i < min($num, $limit)) + { + $obj = $db->fetch_object($result); + + if ($obj->payment_code <> '') + { + $type = '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>'; } - print '</td>'; - if (!$i) $totalarray['nbfield']++; - } - - // Amount - $total = $total + $obj->amount; - print '<td class="nowrap right">'.price($obj->amount).'</td>'; - if (!$i) $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'amount'; - $totalarray['val']['amount'] += $objp->amount; - - // Buttons - print '<td></td>'; - - print '</tr>'; - - $i++; -} - -// Add a buttons placeholder for the total line -$totalarray['nbfield']++; - -// Show total line -include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; - -print '</table>'; -print '</div>'; -print '</form>'; - -$db->free($result); + else + { + $type = '<td> </td>'; + } + + print '<tr class="oddeven">'; + + $tva_static->id = $obj->rowid; + $tva_static->ref = $obj->rowid; + + // Ref + print "<td>".$tva_static->getNomUrl(1)."</td>\n"; + // Label + print "<td>".dol_trunc($obj->label, 40)."</td>\n"; + // Date end period + print '<td class="center">'.dol_print_date($db->jdate($obj->datev), 'day')."</td>\n"; + // Date payment + print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day')."</td>\n"; + // Type + print $type; + // Account + if (!empty($conf->banque->enabled)) + { + print '<td>'; + if ($obj->fk_bank > 0) + { + $bankstatic->id = $obj->bid; + $bankstatic->ref = $obj->bref; + $bankstatic->number = $obj->bnumber; + $bankstatic->account_number = $obj->account_number; + + $accountingjournal = new AccountingJournal($db); + $accountingjournal->fetch($obj->fk_accountancy_journal); + $bankstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1); + + $bankstatic->label = $obj->blabel; + print $bankstatic->getNomUrl(1); + } + else print ' '; + print '</td>'; + } + // Amount + $total = $total + $obj->amount; + print '<td class="nowrap right">'.price($obj->amount)."</td>"; + print "<td> </td>"; + print "</tr>\n"; + + $i++; + } + + $colspan = 5; + if (!empty($conf->banque->enabled)) $colspan++; + print '<tr class="liste_total"><td colspan="'.$colspan.'">'.$langs->trans("Total").'</td>'; + print '<td class="right">'.price($total).'</td>'; + print "<td> </td></tr>"; + + print "</table>"; + print '</div>'; + + print '</form>'; + + $db->free($result); +} +else +{ + dol_print_error($db); +} // End of page llxFooter(); --- /tmp/dsg/dolibarr/htdocs/compta/tva/github_quadri_detail.php +++ /tmp/dsg/dolibarr/htdocs/compta/tva/client_quadri_detail.php @@ -66,11 +66,14 @@ $q = GETPOST("q", "int"); if (empty($q)) { - if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } else { + if (GETPOST("month", "int")) { $date_start = dol_get_first_day($year_start, GETPOST("month", "int"), false); $date_end = dol_get_last_day($year_start, GETPOST("month", "int"), false); } + else + { if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { // quaterly vat, we take last past complete quarter $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -3 - (($current_date['mon'] - $conf->global->SOCIETE_FISCAL_MONTH_START) % 3), 'm'); $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1; - } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat + } + elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { // yearly vat if ($current_date['mon'] < $conf->global->SOCIETE_FISCAL_MONTH_START) { if (($conf->global->SOCIETE_FISCAL_MONTH_START - $current_date['mon']) > 6) { // If period started from less than 6 years, we show past year $year_start--; @@ -82,12 +85,15 @@ } $date_start = dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START, false); $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1; - } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month + } + elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { // monthly vat, we take last past complete month $date_start = dol_time_plus_duree(dol_get_first_day($year_start, $current_date['mon'], false), -1, 'm'); $date_end = dol_time_plus_duree($date_start, 1, 'm') - 1; } } - } else { + } + else + { if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); } if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); } if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); } @@ -152,23 +158,23 @@ if ($modetax == 0) $calcmode = $langs->trans('OptionVATDefault'); if ($modetax == 1) $calcmode = $langs->trans('OptionVATDebitOption'); if ($modetax == 2) $calcmode = $langs->trans('OptionPaymentForProductAndServices'); -$calcmode .= ' <span class="opacitymedium">('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')</span>'; +$calcmode .= '<br>('.$langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT.'/admin/taxes.php').')'; // Set period $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); $prevyear = $year_start; $prevquarter = $q; if ($prevquarter > 1) { $prevquarter--; } else { - $prevquarter = 4; - $prevyear--; + $prevquarter = 4; + $prevyear--; } $nextyear = $year_start; $nextquarter = $q; if ($nextquarter < 4) { $nextquarter++; } else { - $nextquarter = 1; - $nextyear++; + $nextquarter = 1; + $nextyear++; } $description .= $fsearch; $builddate = dol_now(); @@ -213,7 +219,6 @@ // VAT Received and paid -print '<div class="div-table-responsive">'; print '<table class="noborder centpercent">'; $y = $year_current; @@ -310,7 +315,9 @@ 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id], 'link' =>$expensereport->getNomUrl(1) ); - } else { + } + else + { $invoice_supplier->id = $x_paye[$my_paye_rate]['facid'][$id]; $invoice_supplier->ref = $x_paye[$my_paye_rate]['facnum'][$id]; $invoice_supplier->type = $x_paye[$my_paye_rate]['type'][$id]; @@ -432,7 +439,9 @@ if (dol_string_nohtmltag($fields['descr'])) { print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); } - } else { + } + else + { if ($type) { $text = img_object($langs->trans('Service'), 'service'); } else { @@ -611,7 +620,9 @@ if (dol_string_nohtmltag($fields['descr'])) { print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']), 24); } - } else { + } + else + { if ($type) { $text = img_object($langs->trans('Service'), 'service'); } else { @@ -662,7 +673,9 @@ || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) { print $langs->trans("NA"); - } else { + } + else + { if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) { $ratiopaymentinvoice = ($fields['payment_amount'] / $fields['ftotal_ttc']); } @@ -720,7 +733,6 @@ } print '</table>'; - print '</div>'; // Total to pay print '<br><br>';