@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | $startdate=$enddate=''; |
| 59 | 59 | |
| 60 | 60 | if (!empty($_POST['startdatemonth'])) |
| 61 | - $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
| 61 | + $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
| 62 | 62 | if (!empty($_POST['enddatemonth'])) |
| 63 | - $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
| 63 | + $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | /* |
@@ -92,28 +92,28 @@ discard block |
||
| 92 | 92 | $client = false; |
| 93 | 93 | if ($socid > 0) { |
| 94 | 94 | |
| 95 | - $soc = new Societe($db); |
|
| 96 | - $soc->fetch($socid); |
|
| 97 | - |
|
| 98 | - if ($soc->client) |
|
| 99 | - { |
|
| 100 | - print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>'; |
|
| 101 | - print '<td class="maxwidthonsmartphone" colspan="4">'; |
|
| 102 | - print $form->select_company($socid, 'socid', 'client=1 OR client=3', 1, 0, 0); |
|
| 103 | - //$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$socid,$socid,'socid','client=1 OR client=3',1,0,1); |
|
| 104 | - print '</td></tr>'; |
|
| 105 | - |
|
| 106 | - $client = true; |
|
| 107 | - if (! $sortorder) $sortorder="DESC"; |
|
| 108 | - if (! $sortfield) $sortfield="f.datef"; |
|
| 109 | - } |
|
| 95 | + $soc = new Societe($db); |
|
| 96 | + $soc->fetch($socid); |
|
| 97 | + |
|
| 98 | + if ($soc->client) |
|
| 99 | + { |
|
| 100 | + print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>'; |
|
| 101 | + print '<td class="maxwidthonsmartphone" colspan="4">'; |
|
| 102 | + print $form->select_company($socid, 'socid', 'client=1 OR client=3', 1, 0, 0); |
|
| 103 | + //$form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$socid,$socid,'socid','client=1 OR client=3',1,0,1); |
|
| 104 | + print '</td></tr>'; |
|
| 105 | + |
|
| 106 | + $client = true; |
|
| 107 | + if (! $sortorder) $sortorder="DESC"; |
|
| 108 | + if (! $sortfield) $sortfield="f.datef"; |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | else { |
| 112 | - print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>'; |
|
| 113 | - print '<td class="maxwidthonsmartphone" colspan="4">'; |
|
| 114 | - print $form->select_company(null, 'socid', 'client=1 OR client=3', 1, 0, 0); |
|
| 115 | - //$form->form_thirdparty($_SERVER['PHP_SELF'],null,'socid','client=1 OR client=3',1,0,1); |
|
| 116 | - print '</td></tr>'; |
|
| 112 | + print '<tr><td class="titlefield">'.$langs->trans('ThirdPartyName').'</td>'; |
|
| 113 | + print '<td class="maxwidthonsmartphone" colspan="4">'; |
|
| 114 | + print $form->select_company(null, 'socid', 'client=1 OR client=3', 1, 0, 0); |
|
| 115 | + //$form->form_thirdparty($_SERVER['PHP_SELF'],null,'socid','client=1 OR client=3',1,0,1); |
|
| 116 | + print '</td></tr>'; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $sortfield = GETPOST("sortfield",'alpha'); |
@@ -121,16 +121,16 @@ discard block |
||
| 121 | 121 | if (! $sortorder) $sortorder="ASC"; |
| 122 | 122 | if (! $sortfield) |
| 123 | 123 | { |
| 124 | - if ($client) |
|
| 125 | - { |
|
| 126 | - $sortfield="f.datef"; |
|
| 127 | - $sortorder="DESC"; |
|
| 128 | - } |
|
| 129 | - else |
|
| 130 | - { |
|
| 131 | - $sortfield="s.nom"; |
|
| 132 | - $sortorder="ASC"; |
|
| 133 | - } |
|
| 124 | + if ($client) |
|
| 125 | + { |
|
| 126 | + $sortfield="f.datef"; |
|
| 127 | + $sortorder="DESC"; |
|
| 128 | + } |
|
| 129 | + else |
|
| 130 | + { |
|
| 131 | + $sortfield="s.nom"; |
|
| 132 | + $sortorder="ASC"; |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // Products |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | $TProducts = array(); |
| 140 | 140 | foreach($TRes as $prod) { |
| 141 | - $TProducts[$prod['key']] = $prod['label']; |
|
| 141 | + $TProducts[$prod['key']] = $prod['label']; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>'; |
@@ -182,16 +182,16 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | // Margin Rate |
| 184 | 184 | if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
| 185 | - print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">'; |
|
| 186 | - print '<span id="marginRate"></span>'; // set by jquery (see below) |
|
| 187 | - print '</td></tr>'; |
|
| 185 | + print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">'; |
|
| 186 | + print '<span id="marginRate"></span>'; // set by jquery (see below) |
|
| 187 | + print '</td></tr>'; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // Mark Rate |
| 191 | 191 | if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
| 192 | - print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">'; |
|
| 193 | - print '<span id="markRate"></span>'; // set by jquery (see below) |
|
| 194 | - print '</td></tr>'; |
|
| 192 | + print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">'; |
|
| 193 | + print '<span id="markRate"></span>'; // set by jquery (see below) |
|
| 194 | + print '</td></tr>'; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | print "</table>"; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | $sql.= ", ".MAIN_DB_PREFIX."facture as f"; |
| 212 | 212 | $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; |
| 213 | 213 | if(! empty($TSelectedCats)) { |
| 214 | - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product'; |
|
| 214 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=d.fk_product'; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
@@ -223,10 +223,10 @@ discard block |
||
| 223 | 223 | $sql.= " AND d.fk_facture = f.rowid"; |
| 224 | 224 | $sql.= " AND (d.product_type = 0 OR d.product_type = 1)"; |
| 225 | 225 | if(! empty($TSelectedProducts)) { |
| 226 | - $sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts) . ')'; |
|
| 226 | + $sql .= ' AND d.fk_product IN ('.implode(',', $TSelectedProducts) . ')'; |
|
| 227 | 227 | } |
| 228 | 228 | if(! empty($TSelectedCats)) { |
| 229 | - $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')'; |
|
| 229 | + $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')'; |
|
| 230 | 230 | } |
| 231 | 231 | if (!empty($startdate)) |
| 232 | 232 | $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
@@ -245,127 +245,127 @@ discard block |
||
| 245 | 245 | $result = $db->query($sql); |
| 246 | 246 | if ($result) |
| 247 | 247 | { |
| 248 | - $num = $db->num_rows($result); |
|
| 249 | - |
|
| 250 | - print '<br>'; |
|
| 251 | - print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
|
| 252 | - |
|
| 253 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 254 | - $labelcostprice='BuyingPrice'; |
|
| 255 | - else // value is 'costprice' or 'pmp' |
|
| 256 | - $labelcostprice='CostPrice'; |
|
| 257 | - |
|
| 258 | - $i = 0; |
|
| 259 | - print "<table class=\"noborder\" width=\"100%\">"; |
|
| 260 | - |
|
| 261 | - print '<tr class="liste_titre">'; |
|
| 262 | - if (! empty($client)) { |
|
| 263 | - print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 264 | - print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&socid=".$socid,'align="center"',$sortfield,$sortorder); |
|
| 265 | - } |
|
| 266 | - else |
|
| 267 | - print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 268 | - print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 269 | - print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 270 | - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 271 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 272 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 273 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 274 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 275 | - print "</tr>\n"; |
|
| 276 | - |
|
| 277 | - $cumul_achat = 0; |
|
| 278 | - $cumul_vente = 0; |
|
| 279 | - |
|
| 280 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 281 | - |
|
| 282 | - if ($num > 0) |
|
| 283 | - { |
|
| 284 | - while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
| 285 | - { |
|
| 286 | - $objp = $db->fetch_object($result); |
|
| 287 | - |
|
| 288 | - $pa = $objp->buying_price; |
|
| 289 | - $pv = $objp->selling_price; |
|
| 290 | - $marge = $objp->marge; |
|
| 291 | - |
|
| 292 | - if ($marge < 0) |
|
| 293 | - { |
|
| 294 | - $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
| 295 | - $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
| 296 | - } |
|
| 297 | - else |
|
| 298 | - { |
|
| 299 | - $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
| 300 | - $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - print '<tr class="oddeven">'; |
|
| 304 | - if ($client) { |
|
| 305 | - print '<td>'; |
|
| 306 | - $invoicestatic->id=$objp->facid; |
|
| 307 | - $invoicestatic->ref=$objp->ref; |
|
| 308 | - print $invoicestatic->getNomUrl(1); |
|
| 309 | - print "</td>\n"; |
|
| 310 | - print "<td align=\"center\">"; |
|
| 311 | - print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 312 | - } |
|
| 313 | - else { |
|
| 314 | - $companystatic->id=$objp->socid; |
|
| 315 | - $companystatic->name=$objp->name; |
|
| 316 | - $companystatic->client=$objp->client; |
|
| 317 | - print "<td>".$companystatic->getNomUrl(1,'margin')."</td>\n"; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
|
| 321 | - print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
|
| 322 | - print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
|
| 323 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 324 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 325 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 326 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 327 | - print "</tr>\n"; |
|
| 328 | - |
|
| 329 | - $i++; |
|
| 330 | - $cumul_achat += $objp->buying_price; |
|
| 331 | - $cumul_vente += $objp->selling_price; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // affichage totaux marges |
|
| 336 | - |
|
| 337 | - $totalMargin = $cumul_vente - $cumul_achat; |
|
| 338 | - /*if ($totalMargin < 0) |
|
| 248 | + $num = $db->num_rows($result); |
|
| 249 | + |
|
| 250 | + print '<br>'; |
|
| 251 | + print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
|
| 252 | + |
|
| 253 | + if ($conf->global->MARGIN_TYPE == "1") |
|
| 254 | + $labelcostprice='BuyingPrice'; |
|
| 255 | + else // value is 'costprice' or 'pmp' |
|
| 256 | + $labelcostprice='CostPrice'; |
|
| 257 | + |
|
| 258 | + $i = 0; |
|
| 259 | + print "<table class=\"noborder\" width=\"100%\">"; |
|
| 260 | + |
|
| 261 | + print '<tr class="liste_titre">'; |
|
| 262 | + if (! empty($client)) { |
|
| 263 | + print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 264 | + print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&socid=".$socid,'align="center"',$sortfield,$sortorder); |
|
| 265 | + } |
|
| 266 | + else |
|
| 267 | + print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&socid=".$socid,'',$sortfield,$sortorder); |
|
| 268 | + print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 269 | + print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 270 | + print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 271 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 272 | + print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 273 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 274 | + print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&socid=".$socid,'align="right"',$sortfield,$sortorder); |
|
| 275 | + print "</tr>\n"; |
|
| 276 | + |
|
| 277 | + $cumul_achat = 0; |
|
| 278 | + $cumul_vente = 0; |
|
| 279 | + |
|
| 280 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 281 | + |
|
| 282 | + if ($num > 0) |
|
| 283 | + { |
|
| 284 | + while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
| 285 | + { |
|
| 286 | + $objp = $db->fetch_object($result); |
|
| 287 | + |
|
| 288 | + $pa = $objp->buying_price; |
|
| 289 | + $pv = $objp->selling_price; |
|
| 290 | + $marge = $objp->marge; |
|
| 291 | + |
|
| 292 | + if ($marge < 0) |
|
| 293 | + { |
|
| 294 | + $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
| 295 | + $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
| 296 | + } |
|
| 297 | + else |
|
| 298 | + { |
|
| 299 | + $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
| 300 | + $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + print '<tr class="oddeven">'; |
|
| 304 | + if ($client) { |
|
| 305 | + print '<td>'; |
|
| 306 | + $invoicestatic->id=$objp->facid; |
|
| 307 | + $invoicestatic->ref=$objp->ref; |
|
| 308 | + print $invoicestatic->getNomUrl(1); |
|
| 309 | + print "</td>\n"; |
|
| 310 | + print "<td align=\"center\">"; |
|
| 311 | + print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
| 312 | + } |
|
| 313 | + else { |
|
| 314 | + $companystatic->id=$objp->socid; |
|
| 315 | + $companystatic->name=$objp->name; |
|
| 316 | + $companystatic->client=$objp->client; |
|
| 317 | + print "<td>".$companystatic->getNomUrl(1,'margin')."</td>\n"; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
|
| 321 | + print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
|
| 322 | + print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
|
| 323 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 324 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 325 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 326 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 327 | + print "</tr>\n"; |
|
| 328 | + |
|
| 329 | + $i++; |
|
| 330 | + $cumul_achat += $objp->buying_price; |
|
| 331 | + $cumul_vente += $objp->selling_price; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // affichage totaux marges |
|
| 336 | + |
|
| 337 | + $totalMargin = $cumul_vente - $cumul_achat; |
|
| 338 | + /*if ($totalMargin < 0) |
|
| 339 | 339 | { |
| 340 | 340 | $marginRate = ($cumul_achat != 0)?-1*(100 * $totalMargin / $cumul_achat):''; |
| 341 | 341 | $markRate = ($cumul_vente != 0)?-1*(100 * $totalMargin / $cumul_vente):''; |
| 342 | 342 | } |
| 343 | 343 | else |
| 344 | 344 | {*/ |
| 345 | - $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
| 346 | - $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
| 347 | - //} |
|
| 348 | - |
|
| 349 | - print '<tr class="liste_total">'; |
|
| 350 | - if ($client) |
|
| 351 | - print '<td colspan=2>'; |
|
| 352 | - else |
|
| 353 | - print '<td>'; |
|
| 354 | - print $langs->trans('TotalMargin')."</td>"; |
|
| 355 | - print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
|
| 356 | - print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
|
| 357 | - print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
|
| 358 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 359 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 360 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 361 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 362 | - print "</tr>\n"; |
|
| 363 | - |
|
| 364 | - print "</table>"; |
|
| 345 | + $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
| 346 | + $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
| 347 | + //} |
|
| 348 | + |
|
| 349 | + print '<tr class="liste_total">'; |
|
| 350 | + if ($client) |
|
| 351 | + print '<td colspan=2>'; |
|
| 352 | + else |
|
| 353 | + print '<td>'; |
|
| 354 | + print $langs->trans('TotalMargin')."</td>"; |
|
| 355 | + print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
|
| 356 | + print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
|
| 357 | + print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
|
| 358 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 359 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 360 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 361 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
| 362 | + print "</tr>\n"; |
|
| 363 | + |
|
| 364 | + print "</table>"; |
|
| 365 | 365 | } |
| 366 | 366 | else |
| 367 | 367 | { |
| 368 | - dol_print_error($db); |
|
| 368 | + dol_print_error($db); |
|
| 369 | 369 | } |
| 370 | 370 | $db->free($result); |
| 371 | 371 | |
@@ -201,115 +201,115 @@ |
||
| 201 | 201 | $nbtotalofrecords = ''; |
| 202 | 202 | if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { |
| 203 | 203 | |
| 204 | - dol_syslog(__FILE__, LOG_DEBUG); |
|
| 205 | - $result = $db->query($sql); |
|
| 206 | - $nbtotalofrecords = $db->num_rows($result); |
|
| 207 | - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 |
|
| 208 | - { |
|
| 209 | - $page = 0; |
|
| 210 | - $offset = 0; |
|
| 211 | - } |
|
| 204 | + dol_syslog(__FILE__, LOG_DEBUG); |
|
| 205 | + $result = $db->query($sql); |
|
| 206 | + $nbtotalofrecords = $db->num_rows($result); |
|
| 207 | + if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 |
|
| 208 | + { |
|
| 209 | + $page = 0; |
|
| 210 | + $offset = 0; |
|
| 211 | + } |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | $sql .= $db->plimit($limit+1, $offset); |
| 215 | 215 | |
| 216 | 216 | $result = $db->query($sql); |
| 217 | 217 | if ($result) { |
| 218 | - $num = $db->num_rows($result); |
|
| 218 | + $num = $db->num_rows($result); |
|
| 219 | 219 | |
| 220 | - print '<br>'; |
|
| 221 | - print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); |
|
| 220 | + print '<br>'; |
|
| 221 | + print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); |
|
| 222 | 222 | |
| 223 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 224 | - $labelcostprice='BuyingPrice'; |
|
| 225 | - else // value is 'costprice' or 'pmp' |
|
| 226 | - $labelcostprice='CostPrice'; |
|
| 223 | + if ($conf->global->MARGIN_TYPE == "1") |
|
| 224 | + $labelcostprice='BuyingPrice'; |
|
| 225 | + else // value is 'costprice' or 'pmp' |
|
| 226 | + $labelcostprice='CostPrice'; |
|
| 227 | 227 | |
| 228 | - $moreforfilter=''; |
|
| 228 | + $moreforfilter=''; |
|
| 229 | 229 | |
| 230 | - $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; |
|
| 231 | - //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields |
|
| 232 | - //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); |
|
| 233 | - $selectedfields=''; |
|
| 230 | + $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; |
|
| 231 | + //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields |
|
| 232 | + //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); |
|
| 233 | + $selectedfields=''; |
|
| 234 | 234 | |
| 235 | 235 | print '<div class="div-table-responsive">'; |
| 236 | 236 | print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n"; |
| 237 | 237 | |
| 238 | - print '<tr class="liste_titre liste_titre_search">'; |
|
| 239 | - print '<td><input type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>'; |
|
| 240 | - print '<td></td>'; |
|
| 241 | - print '<td></td>'; |
|
| 242 | - print '<td></td>'; |
|
| 243 | - print '<td></td>'; |
|
| 244 | - print '<td></td>'; |
|
| 238 | + print '<tr class="liste_titre liste_titre_search">'; |
|
| 239 | + print '<td><input type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>'; |
|
| 240 | + print '<td></td>'; |
|
| 241 | + print '<td></td>'; |
|
| 242 | + print '<td></td>'; |
|
| 243 | + print '<td></td>'; |
|
| 244 | + print '<td></td>'; |
|
| 245 | 245 | print '<td class="liste_titre" align="middle">'; |
| 246 | 246 | $searchpitco=$form->showFilterButtons(); |
| 247 | 247 | print $searchpitco; |
| 248 | 248 | print '</td>'; |
| 249 | - print "</tr>\n"; |
|
| 250 | - |
|
| 251 | - print '<tr class="liste_titre">'; |
|
| 252 | - print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder); |
|
| 253 | - print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", $param, 'width=20%', $sortfield, $sortorder); |
|
| 254 | - print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "d.subprice", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 255 | - print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 256 | - print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 257 | - print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 258 | - print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch '); |
|
| 259 | - print "</tr>\n"; |
|
| 249 | + print "</tr>\n"; |
|
| 250 | + |
|
| 251 | + print '<tr class="liste_titre">'; |
|
| 252 | + print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder); |
|
| 253 | + print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "", "", $param, 'width=20%', $sortfield, $sortorder); |
|
| 254 | + print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "d.subprice", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 255 | + print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "d.buy_price_ht", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 256 | + print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 257 | + print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder); |
|
| 258 | + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch '); |
|
| 259 | + print "</tr>\n"; |
|
| 260 | 260 | |
| 261 | 261 | $i=0; |
| 262 | - while ($i < min($num, $limit)) |
|
| 263 | - { |
|
| 264 | - $objp = $db->fetch_object($result); |
|
| 265 | - |
|
| 266 | - print '<tr class="oddeven">'; |
|
| 267 | - print '<td>'; |
|
| 268 | - $result_inner = $invoicestatic->fetch($objp->invoiceid); |
|
| 269 | - if ($result_inner < 0) { |
|
| 270 | - setEventMessages($invoicestatic->error, null, 'errors'); |
|
| 271 | - } else { |
|
| 272 | - print $invoicestatic->getNomUrl(1); |
|
| 273 | - } |
|
| 274 | - print '</td>'; |
|
| 275 | - print '<td>'; |
|
| 276 | - if (! empty($objp->fk_product)) { |
|
| 277 | - $result_inner = $productstatic->fetch($objp->fk_product); |
|
| 278 | - if ($result_inner < 0) { |
|
| 279 | - setEventMessages($productstatic->error, null, 'errors'); |
|
| 280 | - } else { |
|
| 281 | - print $productstatic->getNomUrl(1); |
|
| 282 | - } |
|
| 283 | - } else { |
|
| 284 | - print $objp->label; |
|
| 285 | - print ' '; |
|
| 286 | - print $objp->description; |
|
| 287 | - } |
|
| 288 | - print '</td>'; |
|
| 289 | - print '<td align="right">'; |
|
| 290 | - print price($objp->subprice); |
|
| 291 | - print '</td>'; |
|
| 292 | - print '<td align="right">'; |
|
| 293 | - print '<input type="text" name="buyingprice_' . $objp->invoicedetid . '" id="buyingprice_' . $objp->invoicedetid . '" size="6" value="' . price($objp->buy_price_ht) . '" class="right flat">'; |
|
| 294 | - print '</td>'; |
|
| 295 | - print '<td align="right">'; |
|
| 296 | - print $objp->qty; |
|
| 297 | - print '</td>'; |
|
| 298 | - print '<td align="right">'; |
|
| 299 | - print price($objp->total_ht); |
|
| 300 | - print '</td>'; |
|
| 301 | - print '<td></td>'; |
|
| 302 | - |
|
| 303 | - print "</tr>\n"; |
|
| 304 | - |
|
| 305 | - $i ++; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - print "</table>"; |
|
| 309 | - |
|
| 310 | - print "</div>"; |
|
| 262 | + while ($i < min($num, $limit)) |
|
| 263 | + { |
|
| 264 | + $objp = $db->fetch_object($result); |
|
| 265 | + |
|
| 266 | + print '<tr class="oddeven">'; |
|
| 267 | + print '<td>'; |
|
| 268 | + $result_inner = $invoicestatic->fetch($objp->invoiceid); |
|
| 269 | + if ($result_inner < 0) { |
|
| 270 | + setEventMessages($invoicestatic->error, null, 'errors'); |
|
| 271 | + } else { |
|
| 272 | + print $invoicestatic->getNomUrl(1); |
|
| 273 | + } |
|
| 274 | + print '</td>'; |
|
| 275 | + print '<td>'; |
|
| 276 | + if (! empty($objp->fk_product)) { |
|
| 277 | + $result_inner = $productstatic->fetch($objp->fk_product); |
|
| 278 | + if ($result_inner < 0) { |
|
| 279 | + setEventMessages($productstatic->error, null, 'errors'); |
|
| 280 | + } else { |
|
| 281 | + print $productstatic->getNomUrl(1); |
|
| 282 | + } |
|
| 283 | + } else { |
|
| 284 | + print $objp->label; |
|
| 285 | + print ' '; |
|
| 286 | + print $objp->description; |
|
| 287 | + } |
|
| 288 | + print '</td>'; |
|
| 289 | + print '<td align="right">'; |
|
| 290 | + print price($objp->subprice); |
|
| 291 | + print '</td>'; |
|
| 292 | + print '<td align="right">'; |
|
| 293 | + print '<input type="text" name="buyingprice_' . $objp->invoicedetid . '" id="buyingprice_' . $objp->invoicedetid . '" size="6" value="' . price($objp->buy_price_ht) . '" class="right flat">'; |
|
| 294 | + print '</td>'; |
|
| 295 | + print '<td align="right">'; |
|
| 296 | + print $objp->qty; |
|
| 297 | + print '</td>'; |
|
| 298 | + print '<td align="right">'; |
|
| 299 | + print price($objp->total_ht); |
|
| 300 | + print '</td>'; |
|
| 301 | + print '<td></td>'; |
|
| 302 | + |
|
| 303 | + print "</tr>\n"; |
|
| 304 | + |
|
| 305 | + $i ++; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + print "</table>"; |
|
| 309 | + |
|
| 310 | + print "</div>"; |
|
| 311 | 311 | } else { |
| 312 | - dol_print_error($db); |
|
| 312 | + dol_print_error($db); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | |
@@ -29,29 +29,29 @@ |
||
| 29 | 29 | |
| 30 | 30 | if ($action == 'update' && is_array($arrayofparameters)) |
| 31 | 31 | { |
| 32 | - $db->begin(); |
|
| 32 | + $db->begin(); |
|
| 33 | 33 | |
| 34 | - $ok=true; |
|
| 35 | - foreach($arrayofparameters as $key => $val) |
|
| 36 | - { |
|
| 37 | - $result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity); |
|
| 38 | - if ($result < 0) |
|
| 39 | - { |
|
| 40 | - $ok=false; |
|
| 41 | - break; |
|
| 42 | - } |
|
| 43 | - } |
|
| 34 | + $ok=true; |
|
| 35 | + foreach($arrayofparameters as $key => $val) |
|
| 36 | + { |
|
| 37 | + $result=dolibarr_set_const($db,$key,GETPOST($key, 'alpha'),'chaine',0,'',$conf->entity); |
|
| 38 | + if ($result < 0) |
|
| 39 | + { |
|
| 40 | + $ok=false; |
|
| 41 | + break; |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - if (! $error) |
|
| 46 | - { |
|
| 47 | - $db->commit(); |
|
| 48 | - if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
|
| 49 | - } |
|
| 50 | - else |
|
| 51 | - { |
|
| 52 | - $db->rollback(); |
|
| 53 | - if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); |
|
| 54 | - } |
|
| 45 | + if (! $error) |
|
| 46 | + { |
|
| 47 | + $db->commit(); |
|
| 48 | + if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); |
|
| 49 | + } |
|
| 50 | + else |
|
| 51 | + { |
|
| 52 | + $db->rollback(); |
|
| 53 | + if (empty($nomessageinupdate)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); |
|
| 54 | + } |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) |
@@ -27,15 +27,15 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | class InfoBox |
| 29 | 29 | { |
| 30 | - /** |
|
| 31 | - * Name of positions 0=Home, 1=... |
|
| 32 | - * |
|
| 33 | - * @return string[] Array with list of zones |
|
| 34 | - */ |
|
| 35 | - static function getListOfPagesForBoxes() |
|
| 36 | - { |
|
| 37 | - return array(0=>'Home'); |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Name of positions 0=Home, 1=... |
|
| 32 | + * |
|
| 33 | + * @return string[] Array with list of zones |
|
| 34 | + */ |
|
| 35 | + static function getListOfPagesForBoxes() |
|
| 36 | + { |
|
| 37 | + return array(0=>'Home'); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Return array of boxes qualified for area and user |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | $sql.= " ORDER BY b.box_order"; |
| 69 | 69 | } |
| 70 | 70 | else // available |
| 71 | - { |
|
| 71 | + { |
|
| 72 | 72 | $sql = "SELECT d.rowid as box_id, d.file, d.note, d.tms"; |
| 73 | 73 | $sql.= " FROM ".MAIN_DB_PREFIX."boxes_def as d"; |
| 74 | - $sql.= " WHERE d.entity IN (0,".$conf->entity.")"; |
|
| 74 | + $sql.= " WHERE d.entity IN (0,".$conf->entity.")"; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | dol_syslog(get_class()."::listBoxes get default box list for mode=".$mode." userid=".(is_object($user)?$user->id:'')."", LOG_DEBUG); |
@@ -97,17 +97,17 @@ discard block |
||
| 97 | 97 | { |
| 98 | 98 | $boxname=preg_replace('/\.php$/i','',$obj->file); |
| 99 | 99 | $relsourcefile = "/core/boxes/".$boxname.".php"; |
| 100 | - } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - //print $obj->box_id.'-'.$boxname.'-'.$relsourcefile.'<br>'; |
|
| 102 | + //print $obj->box_id.'-'.$boxname.'-'.$relsourcefile.'<br>'; |
|
| 103 | 103 | |
| 104 | - // TODO PERF Do not make "dol_include_once" here, nor "new" later. This means, we must store a 'depends' field to store modules list, then |
|
| 104 | + // TODO PERF Do not make "dol_include_once" here, nor "new" later. This means, we must store a 'depends' field to store modules list, then |
|
| 105 | 105 | // the "enabled" condition for modules forbidden for external users and the depends condition can be done. |
| 106 | 106 | // Goal is to avoid making a "new" done for each boxes returned by select. |
| 107 | 107 | dol_include_once($relsourcefile); |
| 108 | 108 | if (class_exists($boxname)) |
| 109 | 109 | { |
| 110 | - $box=new $boxname($db,$obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params. |
|
| 110 | + $box=new $boxname($db,$obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params. |
|
| 111 | 111 | //$box=new stdClass(); |
| 112 | 112 | |
| 113 | 113 | // box properties |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | $box->box_order = (empty($obj->box_order) ? '' : $obj->box_order); |
| 118 | 118 | $box->fk_user = (empty($obj->fk_user) ? 0 : $obj->fk_user); |
| 119 | 119 | $box->sourcefile= $relsourcefile; |
| 120 | - $box->class = $boxname; |
|
| 120 | + $box->class = $boxname; |
|
| 121 | 121 | |
| 122 | - if ($mode == 'activated' && ! is_object($user)) // List of activated box was not yet personalized into database |
|
| 122 | + if ($mode == 'activated' && ! is_object($user)) // List of activated box was not yet personalized into database |
|
| 123 | 123 | { |
| 124 | 124 | if (is_numeric($box->box_order)) |
| 125 | 125 | { |
@@ -138,19 +138,19 @@ discard block |
||
| 138 | 138 | { |
| 139 | 139 | foreach($box->depends as $moduleelem) |
| 140 | 140 | { |
| 141 | - $arrayelem=explode('|',$moduleelem); |
|
| 142 | - $tmpenabled=0; // $tmpenabled is used for the '|' test (OR) |
|
| 143 | - foreach($arrayelem as $module) |
|
| 144 | - { |
|
| 145 | - $tmpmodule=preg_replace('/@[^@]+/','',$module); |
|
| 146 | - if (! empty($conf->$tmpmodule->enabled)) $tmpenabled=1; |
|
| 147 | - //print $boxname.'-'.$module.'-module enabled='.(empty($conf->$tmpmodule->enabled)?0:1).'<br>'; |
|
| 148 | - } |
|
| 149 | - if (empty($tmpenabled)) // We found at least one module required that is disabled |
|
| 150 | - { |
|
| 151 | - $enabled=0; |
|
| 152 | - break; |
|
| 153 | - } |
|
| 141 | + $arrayelem=explode('|',$moduleelem); |
|
| 142 | + $tmpenabled=0; // $tmpenabled is used for the '|' test (OR) |
|
| 143 | + foreach($arrayelem as $module) |
|
| 144 | + { |
|
| 145 | + $tmpmodule=preg_replace('/@[^@]+/','',$module); |
|
| 146 | + if (! empty($conf->$tmpmodule->enabled)) $tmpenabled=1; |
|
| 147 | + //print $boxname.'-'.$module.'-module enabled='.(empty($conf->$tmpmodule->enabled)?0:1).'<br>'; |
|
| 148 | + } |
|
| 149 | + if (empty($tmpenabled)) // We found at least one module required that is disabled |
|
| 150 | + { |
|
| 151 | + $enabled=0; |
|
| 152 | + break; |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | //print '=>'.$boxname.'-enabled='.$enabled.'<br>'; |
@@ -160,16 +160,16 @@ discard block |
||
| 160 | 160 | else unset($box); |
| 161 | 161 | } |
| 162 | 162 | else |
| 163 | - { |
|
| 164 | - dol_syslog("Failed to load box '".$boxname."' into file '".$relsourcefile."'", LOG_WARNING); |
|
| 165 | - } |
|
| 163 | + { |
|
| 164 | + dol_syslog("Failed to load box '".$boxname."' into file '".$relsourcefile."'", LOG_WARNING); |
|
| 165 | + } |
|
| 166 | 166 | } |
| 167 | 167 | $j++; |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | else |
| 171 | - { |
|
| 172 | - dol_syslog($db->lasterror(),LOG_ERR); |
|
| 171 | + { |
|
| 172 | + dol_syslog($db->lasterror(),LOG_ERR); |
|
| 173 | 173 | return array('error'=>$db->lasterror()); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | public $db; |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * @var string Error code (or message) |
|
| 37 | - */ |
|
| 38 | - public $error=''; |
|
| 36 | + * @var string Error code (or message) |
|
| 37 | + */ |
|
| 38 | + public $error=''; |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -50,99 +50,99 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 53 | - /** |
|
| 54 | - * Show a combo list with contracts qualified for a third party |
|
| 55 | - * |
|
| 56 | - * @param int $socid Id third party (-1=all, 0=only interventions not linked to a third party, id=intervention not linked or linked to third party id) |
|
| 57 | - * @param int $selected Id intervention preselected |
|
| 58 | - * @param string $htmlname Nom de la zone html |
|
| 59 | - * @param int $maxlength Maximum length of label |
|
| 60 | - * @param int $showempty Show empty line |
|
| 61 | - * @return int Nbre of project if OK, <0 if KO |
|
| 62 | - */ |
|
| 63 | - function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1) |
|
| 64 | - { |
|
| 53 | + /** |
|
| 54 | + * Show a combo list with contracts qualified for a third party |
|
| 55 | + * |
|
| 56 | + * @param int $socid Id third party (-1=all, 0=only interventions not linked to a third party, id=intervention not linked or linked to third party id) |
|
| 57 | + * @param int $selected Id intervention preselected |
|
| 58 | + * @param string $htmlname Nom de la zone html |
|
| 59 | + * @param int $maxlength Maximum length of label |
|
| 60 | + * @param int $showempty Show empty line |
|
| 61 | + * @return int Nbre of project if OK, <0 if KO |
|
| 62 | + */ |
|
| 63 | + function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1) |
|
| 64 | + { |
|
| 65 | 65 | // phpcs:enable |
| 66 | - global $db,$user,$conf,$langs; |
|
| 66 | + global $db,$user,$conf,$langs; |
|
| 67 | 67 | |
| 68 | - $out=''; |
|
| 68 | + $out=''; |
|
| 69 | 69 | |
| 70 | - $hideunselectables=false; |
|
| 70 | + $hideunselectables=false; |
|
| 71 | 71 | |
| 72 | - // Search all contacts |
|
| 73 | - $sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut'; |
|
| 74 | - $sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f'; |
|
| 75 | - $sql.= " WHERE f.entity = ".$conf->entity; |
|
| 76 | - if ($socid != '') |
|
| 77 | - { |
|
| 78 | - if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
| 79 | - else $sql.= " AND f.fk_soc = ".$socid; |
|
| 80 | - } |
|
| 72 | + // Search all contacts |
|
| 73 | + $sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut'; |
|
| 74 | + $sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f'; |
|
| 75 | + $sql.= " WHERE f.entity = ".$conf->entity; |
|
| 76 | + if ($socid != '') |
|
| 77 | + { |
|
| 78 | + if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
| 79 | + else $sql.= " AND f.fk_soc = ".$socid; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG); |
|
| 83 | - $resql=$db->query($sql); |
|
| 84 | - if ($resql) |
|
| 85 | - { |
|
| 86 | - $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">'; |
|
| 87 | - if ($showempty) $out.='<option value="0"> </option>'; |
|
| 88 | - $num = $db->num_rows($resql); |
|
| 89 | - $i = 0; |
|
| 90 | - if ($num) |
|
| 91 | - { |
|
| 92 | - while ($i < $num) |
|
| 93 | - { |
|
| 94 | - $obj = $db->fetch_object($resql); |
|
| 95 | - // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. |
|
| 96 | - if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire) |
|
| 97 | - { |
|
| 98 | - // Do nothing |
|
| 99 | - } |
|
| 100 | - else |
|
| 101 | - { |
|
| 102 | - $labeltoshow=dol_trunc($obj->ref,18); |
|
| 103 | - if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
|
| 104 | - { |
|
| 105 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 106 | - } |
|
| 107 | - else |
|
| 108 | - { |
|
| 109 | - $disabled=0; |
|
| 110 | - if (! $obj->fk_statut > 0) |
|
| 111 | - { |
|
| 112 | - $disabled=1; |
|
| 113 | - $labeltoshow.=' ('.$langs->trans("Draft").')'; |
|
| 114 | - } |
|
| 115 | - if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
| 116 | - { |
|
| 117 | - $disabled=1; |
|
| 118 | - $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); |
|
| 119 | - } |
|
| 82 | + dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG); |
|
| 83 | + $resql=$db->query($sql); |
|
| 84 | + if ($resql) |
|
| 85 | + { |
|
| 86 | + $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">'; |
|
| 87 | + if ($showempty) $out.='<option value="0"> </option>'; |
|
| 88 | + $num = $db->num_rows($resql); |
|
| 89 | + $i = 0; |
|
| 90 | + if ($num) |
|
| 91 | + { |
|
| 92 | + while ($i < $num) |
|
| 93 | + { |
|
| 94 | + $obj = $db->fetch_object($resql); |
|
| 95 | + // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. |
|
| 96 | + if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire) |
|
| 97 | + { |
|
| 98 | + // Do nothing |
|
| 99 | + } |
|
| 100 | + else |
|
| 101 | + { |
|
| 102 | + $labeltoshow=dol_trunc($obj->ref,18); |
|
| 103 | + if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
|
| 104 | + { |
|
| 105 | + $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 106 | + } |
|
| 107 | + else |
|
| 108 | + { |
|
| 109 | + $disabled=0; |
|
| 110 | + if (! $obj->fk_statut > 0) |
|
| 111 | + { |
|
| 112 | + $disabled=1; |
|
| 113 | + $labeltoshow.=' ('.$langs->trans("Draft").')'; |
|
| 114 | + } |
|
| 115 | + if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
| 116 | + { |
|
| 117 | + $disabled=1; |
|
| 118 | + $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - if ($hideunselectables && $disabled) |
|
| 122 | - { |
|
| 123 | - $resultat=''; |
|
| 124 | - } |
|
| 125 | - else |
|
| 126 | - { |
|
| 127 | - $resultat='<option value="'.$obj->rowid.'"'; |
|
| 128 | - if ($disabled) $resultat.=' disabled'; |
|
| 129 | - $resultat.='>'.$labeltoshow; |
|
| 130 | - $resultat.='</option>'; |
|
| 131 | - } |
|
| 132 | - $out.=$resultat; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - $i++; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - $out.='</select>'; |
|
| 139 | - $db->free($resql); |
|
| 140 | - return $out; |
|
| 141 | - } |
|
| 142 | - else |
|
| 143 | - { |
|
| 144 | - dol_print_error($db); |
|
| 145 | - return ''; |
|
| 146 | - } |
|
| 147 | - } |
|
| 121 | + if ($hideunselectables && $disabled) |
|
| 122 | + { |
|
| 123 | + $resultat=''; |
|
| 124 | + } |
|
| 125 | + else |
|
| 126 | + { |
|
| 127 | + $resultat='<option value="'.$obj->rowid.'"'; |
|
| 128 | + if ($disabled) $resultat.=' disabled'; |
|
| 129 | + $resultat.='>'.$labeltoshow; |
|
| 130 | + $resultat.='</option>'; |
|
| 131 | + } |
|
| 132 | + $out.=$resultat; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + $i++; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + $out.='</select>'; |
|
| 139 | + $db->free($resql); |
|
| 140 | + return $out; |
|
| 141 | + } |
|
| 142 | + else |
|
| 143 | + { |
|
| 144 | + dol_print_error($db); |
|
| 145 | + return ''; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -36,12 +36,12 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public $db; |
| 38 | 38 | |
| 39 | - var $dir; // Directory with all core and external triggers files |
|
| 39 | + var $dir; // Directory with all core and external triggers files |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | - * @var string[] Error codes (or messages) |
|
| 43 | - */ |
|
| 44 | - public $errors = array(); |
|
| 42 | + * @var string[] Error codes (or messages) |
|
| 43 | + */ |
|
| 44 | + public $errors = array(); |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * Constructor |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | // Check parameters |
| 72 | 72 | if (! is_object($object) || ! is_object($conf)) // Error |
| 73 | 73 | { |
| 74 | - $this->error='function run_triggers called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf); |
|
| 74 | + $this->error='function run_triggers called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf); |
|
| 75 | 75 | dol_syslog(get_class($this).'::run_triggers '.$this->error, LOG_ERR); |
| 76 | - $this->errors[]=$this->error; |
|
| 76 | + $this->errors[]=$this->error; |
|
| 77 | 77 | return -1; |
| 78 | 78 | } |
| 79 | 79 | if (! is_object($langs)) // Warning |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | $files = array(); |
| 93 | 93 | $modules = array(); |
| 94 | 94 | $orders = array(); |
| 95 | - $i=0; |
|
| 95 | + $i=0; |
|
| 96 | 96 | |
| 97 | - $dirtriggers=array_merge(array('/core/triggers'),$conf->modules_parts['triggers']); |
|
| 97 | + $dirtriggers=array_merge(array('/core/triggers'),$conf->modules_parts['triggers']); |
|
| 98 | 98 | foreach($dirtriggers as $reldir) |
| 99 | 99 | { |
| 100 | 100 | $dir=dol_buildpath($reldir,0); |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | { |
| 112 | 112 | if (is_readable($newdir."/".$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php$/i',$file,$reg)) |
| 113 | 113 | { |
| 114 | - $part1=$reg[1]; |
|
| 115 | - $part2=$reg[2]; |
|
| 116 | - $part3=$reg[3]; |
|
| 114 | + $part1=$reg[1]; |
|
| 115 | + $part2=$reg[2]; |
|
| 116 | + $part3=$reg[3]; |
|
| 117 | 117 | |
| 118 | 118 | $nbfile++; |
| 119 | 119 | |
@@ -175,22 +175,22 @@ discard block |
||
| 175 | 175 | $objMod = new $modName($this->db); |
| 176 | 176 | if ($objMod) |
| 177 | 177 | { |
| 178 | - $result=0; |
|
| 179 | - |
|
| 180 | - if (method_exists($objMod, 'runTrigger')) // New method to implement |
|
| 181 | - { |
|
| 182 | - //dol_syslog(get_class($this)."::run_triggers action=".$action." Launch runTrigger for file '".$files[$key]."'", LOG_DEBUG); |
|
| 183 | - $result=$objMod->runTrigger($action,$object,$user,$langs,$conf); |
|
| 184 | - } |
|
| 185 | - elseif (method_exists($objMod, 'run_trigger')) // Deprecated method |
|
| 186 | - { |
|
| 187 | - dol_syslog(get_class($this)."::run_triggers action=".$action." Launch old method run_trigger (rename your trigger into runTrigger) for file '".$files[$key]."'", LOG_WARNING); |
|
| 188 | - $result=$objMod->run_trigger($action,$object,$user,$langs,$conf); |
|
| 189 | - } |
|
| 190 | - else |
|
| 191 | - { |
|
| 192 | - dol_syslog(get_class($this)."::run_triggers action=".$action." A trigger was declared for class ".get_class($objMod)." but method runTrigger was not found", LOG_ERR); |
|
| 193 | - } |
|
| 178 | + $result=0; |
|
| 179 | + |
|
| 180 | + if (method_exists($objMod, 'runTrigger')) // New method to implement |
|
| 181 | + { |
|
| 182 | + //dol_syslog(get_class($this)."::run_triggers action=".$action." Launch runTrigger for file '".$files[$key]."'", LOG_DEBUG); |
|
| 183 | + $result=$objMod->runTrigger($action,$object,$user,$langs,$conf); |
|
| 184 | + } |
|
| 185 | + elseif (method_exists($objMod, 'run_trigger')) // Deprecated method |
|
| 186 | + { |
|
| 187 | + dol_syslog(get_class($this)."::run_triggers action=".$action." Launch old method run_trigger (rename your trigger into runTrigger) for file '".$files[$key]."'", LOG_WARNING); |
|
| 188 | + $result=$objMod->run_trigger($action,$object,$user,$langs,$conf); |
|
| 189 | + } |
|
| 190 | + else |
|
| 191 | + { |
|
| 192 | + dol_syslog(get_class($this)."::run_triggers action=".$action." A trigger was declared for class ".get_class($objMod)." but method runTrigger was not found", LOG_ERR); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | 195 | if ($result > 0) |
| 196 | 196 | { |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | else |
| 218 | - { |
|
| 218 | + { |
|
| 219 | 219 | dol_syslog(get_class($this)."::run_triggers action=".$action." Failed to instantiate trigger for file '".$files[$key]."'", LOG_ERR); |
| 220 | 220 | } |
| 221 | 221 | } |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | $dirtriggers=array_merge(array('/core/triggers/'),$conf->modules_parts['triggers']); |
| 255 | 255 | if (is_array($forcedirtriggers)) |
| 256 | 256 | { |
| 257 | - $dirtriggers=$forcedirtriggers; |
|
| 257 | + $dirtriggers=$forcedirtriggers; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | foreach($dirtriggers as $reldir) |
@@ -274,9 +274,9 @@ discard block |
||
| 274 | 274 | { |
| 275 | 275 | if (preg_match('/\.back$/',$file)) continue; |
| 276 | 276 | |
| 277 | - $part1=$reg[1]; |
|
| 278 | - $part2=$reg[2]; |
|
| 279 | - $part3=$reg[3]; |
|
| 277 | + $part1=$reg[1]; |
|
| 278 | + $part2=$reg[2]; |
|
| 279 | + $part3=$reg[3]; |
|
| 280 | 280 | |
| 281 | 281 | $modName = 'Interface'.ucfirst($reg[3]); |
| 282 | 282 | //print "file=$file"; print "modName=$modName"; exit; |
@@ -317,8 +317,8 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | if (! class_exists($modName)) |
| 319 | 319 | { |
| 320 | - print 'Error: A trigger file was found but its class "'.$modName.'" was not found.'."<br>\n"; |
|
| 321 | - continue; |
|
| 320 | + print 'Error: A trigger file was found but its class "'.$modName.'" was not found.'."<br>\n"; |
|
| 321 | + continue; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | $objMod = new $modName($db); |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | $triggers[$j]['module']=strtolower($module); |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - // We set info of modules |
|
| 343 | + // We set info of modules |
|
| 344 | 344 | $triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic'); |
| 345 | 345 | $triggers[$j]['file'] = $files[$key]; |
| 346 | 346 | $triggers[$j]['fullpath'] = $fullpath[$key]; |
@@ -26,63 +26,63 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class GoogleAPI |
| 28 | 28 | { |
| 29 | - /** |
|
| 29 | + /** |
|
| 30 | 30 | * @var DoliDB Database handler. |
| 31 | 31 | */ |
| 32 | 32 | public $db; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var string Error code (or message) |
|
| 36 | - */ |
|
| 37 | - public $error=''; |
|
| 34 | + /** |
|
| 35 | + * @var string Error code (or message) |
|
| 36 | + */ |
|
| 37 | + public $error=''; |
|
| 38 | 38 | |
| 39 | - public $key; |
|
| 39 | + public $key; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Constructor |
|
| 43 | - * |
|
| 44 | - * @param DoliDB $db Database handler |
|
| 45 | - * @param string $key Google key |
|
| 46 | - */ |
|
| 47 | - function __construct($db,$key) |
|
| 48 | - { |
|
| 49 | - $this->db=$db; |
|
| 50 | - $this->key=$key; |
|
| 51 | - } |
|
| 41 | + /** |
|
| 42 | + * Constructor |
|
| 43 | + * |
|
| 44 | + * @param DoliDB $db Database handler |
|
| 45 | + * @param string $key Google key |
|
| 46 | + */ |
|
| 47 | + function __construct($db,$key) |
|
| 48 | + { |
|
| 49 | + $this->db=$db; |
|
| 50 | + $this->key=$key; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Return geo coordinates of an address |
|
| 56 | - * |
|
| 57 | - * @param string $address Address |
|
| 58 | - * Example: 68 Grande rue Charles de Gaulle,+94130,+Nogent sur Marne,+France |
|
| 59 | - * Example: 188, rue de Fontenay,+94300,+Vincennes,+France |
|
| 60 | - * @return string Coordinates |
|
| 61 | - */ |
|
| 62 | - function getGeoCoordinatesOfAddress($address) |
|
| 63 | - { |
|
| 64 | - global $conf; |
|
| 54 | + /** |
|
| 55 | + * Return geo coordinates of an address |
|
| 56 | + * |
|
| 57 | + * @param string $address Address |
|
| 58 | + * Example: 68 Grande rue Charles de Gaulle,+94130,+Nogent sur Marne,+France |
|
| 59 | + * Example: 188, rue de Fontenay,+94300,+Vincennes,+France |
|
| 60 | + * @return string Coordinates |
|
| 61 | + */ |
|
| 62 | + function getGeoCoordinatesOfAddress($address) |
|
| 63 | + { |
|
| 64 | + global $conf; |
|
| 65 | 65 | |
| 66 | - $i=0; |
|
| 66 | + $i=0; |
|
| 67 | 67 | |
| 68 | - // Desired address |
|
| 69 | - $urladdress = "https://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml&key=".$this->key; |
|
| 68 | + // Desired address |
|
| 69 | + $urladdress = "https://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml&key=".$this->key; |
|
| 70 | 70 | |
| 71 | - // Retrieve the URL contents |
|
| 72 | - $page = file_get_contents($urladdress); |
|
| 71 | + // Retrieve the URL contents |
|
| 72 | + $page = file_get_contents($urladdress); |
|
| 73 | 73 | |
| 74 | - $code = strstr($page, '<coordinates>'); |
|
| 75 | - $code = strstr($code, '>'); |
|
| 76 | - $val=strpos($code, "<"); |
|
| 77 | - $code = substr($code, 1, $val-1); |
|
| 78 | - //print $code; |
|
| 79 | - //print "<br>"; |
|
| 80 | - $latitude = substr($code, 0, strpos($code, ",")); |
|
| 81 | - $longitude = substr($code, strpos($code, ",")+1, dol_strlen(strpos($code, ","))-3); |
|
| 74 | + $code = strstr($page, '<coordinates>'); |
|
| 75 | + $code = strstr($code, '>'); |
|
| 76 | + $val=strpos($code, "<"); |
|
| 77 | + $code = substr($code, 1, $val-1); |
|
| 78 | + //print $code; |
|
| 79 | + //print "<br>"; |
|
| 80 | + $latitude = substr($code, 0, strpos($code, ",")); |
|
| 81 | + $longitude = substr($code, strpos($code, ",")+1, dol_strlen(strpos($code, ","))-3); |
|
| 82 | 82 | |
| 83 | - // Output the coordinates |
|
| 84 | - //echo "Longitude: $longitude ',' Latitude: $latitude"; |
|
| 83 | + // Output the coordinates |
|
| 84 | + //echo "Longitude: $longitude ',' Latitude: $latitude"; |
|
| 85 | 85 | |
| 86 | - $i++; |
|
| 87 | - } |
|
| 86 | + $i++; |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -61,624 +61,624 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | const TYPE_SITUATION = 5; |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Draft status |
|
| 66 | - */ |
|
| 67 | - const STATUS_DRAFT = 0; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Validated (need to be paid) |
|
| 71 | - */ |
|
| 72 | - const STATUS_VALIDATED = 1; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Classified paid. |
|
| 76 | - * If paid partially, $this->close_code can be: |
|
| 77 | - * - CLOSECODE_DISCOUNTVAT |
|
| 78 | - * - CLOSECODE_BADDEBT |
|
| 79 | - * If paid completelly, this->close_code will be null |
|
| 80 | - */ |
|
| 81 | - const STATUS_CLOSED = 2; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Classified abandoned and no payment done. |
|
| 85 | - * $this->close_code can be: |
|
| 86 | - * - CLOSECODE_BADDEBT |
|
| 87 | - * - CLOSECODE_ABANDONED |
|
| 88 | - * - CLOSECODE_REPLACED |
|
| 89 | - */ |
|
| 90 | - const STATUS_ABANDONED = 3; |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Return remain amount to pay. Property ->id and ->total_ttc must be set. |
|
| 95 | - * This does not include open direct debit requests. |
|
| 96 | - * |
|
| 97 | - * @param int $multicurrency Return multicurrency_amount instead of amount |
|
| 98 | - * @return double Remain of amount to pay |
|
| 99 | - */ |
|
| 100 | - function getRemainToPay($multicurrency=0) |
|
| 101 | - { |
|
| 102 | - $alreadypaid=0; |
|
| 103 | - $alreadypaid+=$this->getSommePaiement($multicurrency); |
|
| 104 | - $alreadypaid+=$this->getSumDepositsUsed($multicurrency); |
|
| 105 | - $alreadypaid+=$this->getSumCreditNotesUsed($multicurrency); |
|
| 106 | - return $this->total_ttc - $alreadypaid; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Return amount of payments already done |
|
| 111 | - * |
|
| 112 | - * @param int $multicurrency Return multicurrency_amount instead of amount |
|
| 113 | - * @return int Amount of payment already done, <0 if KO |
|
| 114 | - */ |
|
| 115 | - function getSommePaiement($multicurrency=0) |
|
| 116 | - { |
|
| 117 | - $table='paiement_facture'; |
|
| 118 | - $field='fk_facture'; |
|
| 119 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
| 120 | - { |
|
| 121 | - $table='paiementfourn_facturefourn'; |
|
| 122 | - $field='fk_facturefourn'; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $sql = 'SELECT sum(amount) as amount, sum(multicurrency_amount) as multicurrency_amount'; |
|
| 126 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$table; |
|
| 127 | - $sql.= ' WHERE '.$field.' = '.$this->id; |
|
| 128 | - |
|
| 129 | - dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG); |
|
| 130 | - $resql=$this->db->query($sql); |
|
| 131 | - if ($resql) |
|
| 132 | - { |
|
| 133 | - $obj = $this->db->fetch_object($resql); |
|
| 134 | - $this->db->free($resql); |
|
| 135 | - if ($multicurrency) return $obj->multicurrency_amount; |
|
| 136 | - else return $obj->amount; |
|
| 137 | - } |
|
| 138 | - else |
|
| 139 | - { |
|
| 140 | - $this->error=$this->db->lasterror(); |
|
| 141 | - return -1; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Return amount (with tax) of all deposits invoices used by invoice. |
|
| 64 | + /** |
|
| 65 | + * Draft status |
|
| 66 | + */ |
|
| 67 | + const STATUS_DRAFT = 0; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Validated (need to be paid) |
|
| 71 | + */ |
|
| 72 | + const STATUS_VALIDATED = 1; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Classified paid. |
|
| 76 | + * If paid partially, $this->close_code can be: |
|
| 77 | + * - CLOSECODE_DISCOUNTVAT |
|
| 78 | + * - CLOSECODE_BADDEBT |
|
| 79 | + * If paid completelly, this->close_code will be null |
|
| 80 | + */ |
|
| 81 | + const STATUS_CLOSED = 2; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Classified abandoned and no payment done. |
|
| 85 | + * $this->close_code can be: |
|
| 86 | + * - CLOSECODE_BADDEBT |
|
| 87 | + * - CLOSECODE_ABANDONED |
|
| 88 | + * - CLOSECODE_REPLACED |
|
| 89 | + */ |
|
| 90 | + const STATUS_ABANDONED = 3; |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Return remain amount to pay. Property ->id and ->total_ttc must be set. |
|
| 95 | + * This does not include open direct debit requests. |
|
| 96 | + * |
|
| 97 | + * @param int $multicurrency Return multicurrency_amount instead of amount |
|
| 98 | + * @return double Remain of amount to pay |
|
| 99 | + */ |
|
| 100 | + function getRemainToPay($multicurrency=0) |
|
| 101 | + { |
|
| 102 | + $alreadypaid=0; |
|
| 103 | + $alreadypaid+=$this->getSommePaiement($multicurrency); |
|
| 104 | + $alreadypaid+=$this->getSumDepositsUsed($multicurrency); |
|
| 105 | + $alreadypaid+=$this->getSumCreditNotesUsed($multicurrency); |
|
| 106 | + return $this->total_ttc - $alreadypaid; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Return amount of payments already done |
|
| 111 | + * |
|
| 112 | + * @param int $multicurrency Return multicurrency_amount instead of amount |
|
| 113 | + * @return int Amount of payment already done, <0 if KO |
|
| 114 | + */ |
|
| 115 | + function getSommePaiement($multicurrency=0) |
|
| 116 | + { |
|
| 117 | + $table='paiement_facture'; |
|
| 118 | + $field='fk_facture'; |
|
| 119 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
| 120 | + { |
|
| 121 | + $table='paiementfourn_facturefourn'; |
|
| 122 | + $field='fk_facturefourn'; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $sql = 'SELECT sum(amount) as amount, sum(multicurrency_amount) as multicurrency_amount'; |
|
| 126 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$table; |
|
| 127 | + $sql.= ' WHERE '.$field.' = '.$this->id; |
|
| 128 | + |
|
| 129 | + dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG); |
|
| 130 | + $resql=$this->db->query($sql); |
|
| 131 | + if ($resql) |
|
| 132 | + { |
|
| 133 | + $obj = $this->db->fetch_object($resql); |
|
| 134 | + $this->db->free($resql); |
|
| 135 | + if ($multicurrency) return $obj->multicurrency_amount; |
|
| 136 | + else return $obj->amount; |
|
| 137 | + } |
|
| 138 | + else |
|
| 139 | + { |
|
| 140 | + $this->error=$this->db->lasterror(); |
|
| 141 | + return -1; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Return amount (with tax) of all deposits invoices used by invoice. |
|
| 147 | 147 | * Should always be empty, except if option FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is on (not recommended). |
| 148 | - * |
|
| 149 | - * @param int $multicurrency Return multicurrency_amount instead of amount |
|
| 150 | - * @return int <0 if KO, Sum of deposits amount otherwise |
|
| 151 | - */ |
|
| 152 | - function getSumDepositsUsed($multicurrency=0) |
|
| 153 | - { |
|
| 154 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
| 155 | - { |
|
| 156 | - // TODO |
|
| 157 | - return 0; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; |
|
| 161 | - |
|
| 162 | - $discountstatic=new DiscountAbsolute($this->db); |
|
| 163 | - $result=$discountstatic->getSumDepositsUsed($this, $multicurrency); |
|
| 164 | - if ($result >= 0) |
|
| 165 | - { |
|
| 166 | - return $result; |
|
| 167 | - } |
|
| 168 | - else |
|
| 169 | - { |
|
| 170 | - $this->error=$discountstatic->error; |
|
| 171 | - return -1; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Return amount (with tax) of all credit notes invoices + excess received used by invoice |
|
| 177 | - * |
|
| 178 | - * @param int $multicurrency Return multicurrency_amount instead of amount |
|
| 179 | - * @return int <0 if KO, Sum of credit notes and deposits amount otherwise |
|
| 180 | - */ |
|
| 181 | - function getSumCreditNotesUsed($multicurrency=0) |
|
| 182 | - { |
|
| 183 | - require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; |
|
| 184 | - |
|
| 185 | - $discountstatic=new DiscountAbsolute($this->db); |
|
| 186 | - $result=$discountstatic->getSumCreditNotesUsed($this, $multicurrency); |
|
| 187 | - if ($result >= 0) |
|
| 188 | - { |
|
| 189 | - return $result; |
|
| 190 | - } |
|
| 191 | - else |
|
| 192 | - { |
|
| 193 | - $this->error=$discountstatic->error; |
|
| 194 | - return -1; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Renvoie tableau des ids de facture avoir issus de la facture |
|
| 200 | - * |
|
| 201 | - * @return array Tableau d'id de factures avoirs |
|
| 202 | - */ |
|
| 203 | - function getListIdAvoirFromInvoice() |
|
| 204 | - { |
|
| 205 | - $idarray=array(); |
|
| 206 | - |
|
| 207 | - $sql = 'SELECT rowid'; |
|
| 208 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 209 | - $sql.= ' WHERE fk_facture_source = '.$this->id; |
|
| 210 | - $sql.= ' AND type = 2'; |
|
| 211 | - $resql=$this->db->query($sql); |
|
| 212 | - if ($resql) |
|
| 213 | - { |
|
| 214 | - $num = $this->db->num_rows($resql); |
|
| 215 | - $i = 0; |
|
| 216 | - while ($i < $num) |
|
| 217 | - { |
|
| 218 | - $row = $this->db->fetch_row($resql); |
|
| 219 | - $idarray[]=$row[0]; |
|
| 220 | - $i++; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - else |
|
| 224 | - { |
|
| 225 | - dol_print_error($this->db); |
|
| 226 | - } |
|
| 227 | - return $idarray; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Renvoie l'id de la facture qui la remplace |
|
| 232 | - * |
|
| 233 | - * @param string $option filtre sur statut ('', 'validated', ...) |
|
| 234 | - * @return int <0 si KO, 0 si aucune facture ne remplace, id facture sinon |
|
| 235 | - */ |
|
| 236 | - function getIdReplacingInvoice($option='') |
|
| 237 | - { |
|
| 238 | - $sql = 'SELECT rowid'; |
|
| 239 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 240 | - $sql.= ' WHERE fk_facture_source = '.$this->id; |
|
| 241 | - $sql.= ' AND type < 2'; |
|
| 242 | - if ($option == 'validated') $sql.= ' AND fk_statut = 1'; |
|
| 243 | - // PROTECTION BAD DATA |
|
| 244 | - // Au cas ou base corrompue et qu'il y a une facture de remplacement validee |
|
| 245 | - // et une autre non, on donne priorite a la validee. |
|
| 246 | - // Ne devrait pas arriver (sauf si acces concurrentiel et que 2 personnes |
|
| 247 | - // ont cree en meme temps une facture de remplacement pour la meme facture) |
|
| 248 | - $sql.= ' ORDER BY fk_statut DESC'; |
|
| 249 | - |
|
| 250 | - $resql=$this->db->query($sql); |
|
| 251 | - if ($resql) |
|
| 252 | - { |
|
| 253 | - $obj = $this->db->fetch_object($resql); |
|
| 254 | - if ($obj) |
|
| 255 | - { |
|
| 256 | - // Si il y en a |
|
| 257 | - return $obj->rowid; |
|
| 258 | - } |
|
| 259 | - else |
|
| 260 | - { |
|
| 261 | - // Si aucune facture ne remplace |
|
| 262 | - return 0; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - else |
|
| 266 | - { |
|
| 267 | - return -1; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Return list of payments |
|
| 273 | - * |
|
| 274 | - * @param string $filtertype 1 to filter on type of payment == 'PRE' |
|
| 275 | - * @return array Array with list of payments |
|
| 276 | - */ |
|
| 277 | - function getListOfPayments($filtertype='') |
|
| 278 | - { |
|
| 279 | - $retarray=array(); |
|
| 280 | - |
|
| 281 | - $table='paiement_facture'; |
|
| 282 | - $table2='paiement'; |
|
| 283 | - $field='fk_facture'; |
|
| 284 | - $field2='fk_paiement'; |
|
| 285 | - $sharedentity='facture'; |
|
| 286 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
| 287 | - { |
|
| 288 | - $table='paiementfourn_facturefourn'; |
|
| 289 | - $table2='paiementfourn'; |
|
| 290 | - $field='fk_facturefourn'; |
|
| 291 | - $field2='fk_paiementfourn'; |
|
| 292 | - $sharedentity='facture_fourn'; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $sql = 'SELECT p.ref, pf.amount, pf.multicurrency_amount, p.fk_paiement, p.datep, p.num_paiement as num, t.code'; |
|
| 296 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$table.' as pf, '.MAIN_DB_PREFIX.$table2.' as p, '.MAIN_DB_PREFIX.'c_paiement as t'; |
|
| 297 | - $sql.= ' WHERE pf.'.$field.' = '.$this->id; |
|
| 298 | - //$sql.= ' WHERE pf.'.$field.' = 1'; |
|
| 299 | - $sql.= ' AND pf.'.$field2.' = p.rowid'; |
|
| 300 | - $sql.= ' AND p.fk_paiement = t.id'; |
|
| 301 | - $sql.= ' AND p.entity IN (' . getEntity($sharedentity).')'; |
|
| 302 | - if ($filtertype) $sql.=" AND t.code='PRE'"; |
|
| 303 | - |
|
| 304 | - dol_syslog(get_class($this)."::getListOfPayments", LOG_DEBUG); |
|
| 305 | - $resql=$this->db->query($sql); |
|
| 306 | - if ($resql) |
|
| 307 | - { |
|
| 308 | - $num = $this->db->num_rows($resql); |
|
| 309 | - $i=0; |
|
| 310 | - while ($i < $num) |
|
| 311 | - { |
|
| 312 | - $obj = $this->db->fetch_object($resql); |
|
| 313 | - $retarray[]=array('amount'=>$obj->amount,'type'=>$obj->code, 'date'=>$obj->datep, 'num'=>$obj->num, 'ref'=>$obj->ref); |
|
| 314 | - $i++; |
|
| 315 | - } |
|
| 316 | - $this->db->free($resql); |
|
| 317 | - return $retarray; |
|
| 318 | - } |
|
| 319 | - else |
|
| 320 | - { |
|
| 321 | - $this->error=$this->db->lasterror(); |
|
| 322 | - dol_print_error($this->db); |
|
| 323 | - return array(); |
|
| 324 | - } |
|
| 325 | - } |
|
| 148 | + * |
|
| 149 | + * @param int $multicurrency Return multicurrency_amount instead of amount |
|
| 150 | + * @return int <0 if KO, Sum of deposits amount otherwise |
|
| 151 | + */ |
|
| 152 | + function getSumDepositsUsed($multicurrency=0) |
|
| 153 | + { |
|
| 154 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
| 155 | + { |
|
| 156 | + // TODO |
|
| 157 | + return 0; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; |
|
| 161 | + |
|
| 162 | + $discountstatic=new DiscountAbsolute($this->db); |
|
| 163 | + $result=$discountstatic->getSumDepositsUsed($this, $multicurrency); |
|
| 164 | + if ($result >= 0) |
|
| 165 | + { |
|
| 166 | + return $result; |
|
| 167 | + } |
|
| 168 | + else |
|
| 169 | + { |
|
| 170 | + $this->error=$discountstatic->error; |
|
| 171 | + return -1; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Return amount (with tax) of all credit notes invoices + excess received used by invoice |
|
| 177 | + * |
|
| 178 | + * @param int $multicurrency Return multicurrency_amount instead of amount |
|
| 179 | + * @return int <0 if KO, Sum of credit notes and deposits amount otherwise |
|
| 180 | + */ |
|
| 181 | + function getSumCreditNotesUsed($multicurrency=0) |
|
| 182 | + { |
|
| 183 | + require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; |
|
| 184 | + |
|
| 185 | + $discountstatic=new DiscountAbsolute($this->db); |
|
| 186 | + $result=$discountstatic->getSumCreditNotesUsed($this, $multicurrency); |
|
| 187 | + if ($result >= 0) |
|
| 188 | + { |
|
| 189 | + return $result; |
|
| 190 | + } |
|
| 191 | + else |
|
| 192 | + { |
|
| 193 | + $this->error=$discountstatic->error; |
|
| 194 | + return -1; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Renvoie tableau des ids de facture avoir issus de la facture |
|
| 200 | + * |
|
| 201 | + * @return array Tableau d'id de factures avoirs |
|
| 202 | + */ |
|
| 203 | + function getListIdAvoirFromInvoice() |
|
| 204 | + { |
|
| 205 | + $idarray=array(); |
|
| 206 | + |
|
| 207 | + $sql = 'SELECT rowid'; |
|
| 208 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 209 | + $sql.= ' WHERE fk_facture_source = '.$this->id; |
|
| 210 | + $sql.= ' AND type = 2'; |
|
| 211 | + $resql=$this->db->query($sql); |
|
| 212 | + if ($resql) |
|
| 213 | + { |
|
| 214 | + $num = $this->db->num_rows($resql); |
|
| 215 | + $i = 0; |
|
| 216 | + while ($i < $num) |
|
| 217 | + { |
|
| 218 | + $row = $this->db->fetch_row($resql); |
|
| 219 | + $idarray[]=$row[0]; |
|
| 220 | + $i++; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + else |
|
| 224 | + { |
|
| 225 | + dol_print_error($this->db); |
|
| 226 | + } |
|
| 227 | + return $idarray; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Renvoie l'id de la facture qui la remplace |
|
| 232 | + * |
|
| 233 | + * @param string $option filtre sur statut ('', 'validated', ...) |
|
| 234 | + * @return int <0 si KO, 0 si aucune facture ne remplace, id facture sinon |
|
| 235 | + */ |
|
| 236 | + function getIdReplacingInvoice($option='') |
|
| 237 | + { |
|
| 238 | + $sql = 'SELECT rowid'; |
|
| 239 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 240 | + $sql.= ' WHERE fk_facture_source = '.$this->id; |
|
| 241 | + $sql.= ' AND type < 2'; |
|
| 242 | + if ($option == 'validated') $sql.= ' AND fk_statut = 1'; |
|
| 243 | + // PROTECTION BAD DATA |
|
| 244 | + // Au cas ou base corrompue et qu'il y a une facture de remplacement validee |
|
| 245 | + // et une autre non, on donne priorite a la validee. |
|
| 246 | + // Ne devrait pas arriver (sauf si acces concurrentiel et que 2 personnes |
|
| 247 | + // ont cree en meme temps une facture de remplacement pour la meme facture) |
|
| 248 | + $sql.= ' ORDER BY fk_statut DESC'; |
|
| 249 | + |
|
| 250 | + $resql=$this->db->query($sql); |
|
| 251 | + if ($resql) |
|
| 252 | + { |
|
| 253 | + $obj = $this->db->fetch_object($resql); |
|
| 254 | + if ($obj) |
|
| 255 | + { |
|
| 256 | + // Si il y en a |
|
| 257 | + return $obj->rowid; |
|
| 258 | + } |
|
| 259 | + else |
|
| 260 | + { |
|
| 261 | + // Si aucune facture ne remplace |
|
| 262 | + return 0; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + else |
|
| 266 | + { |
|
| 267 | + return -1; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Return list of payments |
|
| 273 | + * |
|
| 274 | + * @param string $filtertype 1 to filter on type of payment == 'PRE' |
|
| 275 | + * @return array Array with list of payments |
|
| 276 | + */ |
|
| 277 | + function getListOfPayments($filtertype='') |
|
| 278 | + { |
|
| 279 | + $retarray=array(); |
|
| 280 | + |
|
| 281 | + $table='paiement_facture'; |
|
| 282 | + $table2='paiement'; |
|
| 283 | + $field='fk_facture'; |
|
| 284 | + $field2='fk_paiement'; |
|
| 285 | + $sharedentity='facture'; |
|
| 286 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
| 287 | + { |
|
| 288 | + $table='paiementfourn_facturefourn'; |
|
| 289 | + $table2='paiementfourn'; |
|
| 290 | + $field='fk_facturefourn'; |
|
| 291 | + $field2='fk_paiementfourn'; |
|
| 292 | + $sharedentity='facture_fourn'; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $sql = 'SELECT p.ref, pf.amount, pf.multicurrency_amount, p.fk_paiement, p.datep, p.num_paiement as num, t.code'; |
|
| 296 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$table.' as pf, '.MAIN_DB_PREFIX.$table2.' as p, '.MAIN_DB_PREFIX.'c_paiement as t'; |
|
| 297 | + $sql.= ' WHERE pf.'.$field.' = '.$this->id; |
|
| 298 | + //$sql.= ' WHERE pf.'.$field.' = 1'; |
|
| 299 | + $sql.= ' AND pf.'.$field2.' = p.rowid'; |
|
| 300 | + $sql.= ' AND p.fk_paiement = t.id'; |
|
| 301 | + $sql.= ' AND p.entity IN (' . getEntity($sharedentity).')'; |
|
| 302 | + if ($filtertype) $sql.=" AND t.code='PRE'"; |
|
| 303 | + |
|
| 304 | + dol_syslog(get_class($this)."::getListOfPayments", LOG_DEBUG); |
|
| 305 | + $resql=$this->db->query($sql); |
|
| 306 | + if ($resql) |
|
| 307 | + { |
|
| 308 | + $num = $this->db->num_rows($resql); |
|
| 309 | + $i=0; |
|
| 310 | + while ($i < $num) |
|
| 311 | + { |
|
| 312 | + $obj = $this->db->fetch_object($resql); |
|
| 313 | + $retarray[]=array('amount'=>$obj->amount,'type'=>$obj->code, 'date'=>$obj->datep, 'num'=>$obj->num, 'ref'=>$obj->ref); |
|
| 314 | + $i++; |
|
| 315 | + } |
|
| 316 | + $this->db->free($resql); |
|
| 317 | + return $retarray; |
|
| 318 | + } |
|
| 319 | + else |
|
| 320 | + { |
|
| 321 | + $this->error=$this->db->lasterror(); |
|
| 322 | + dol_print_error($this->db); |
|
| 323 | + return array(); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | 327 | |
| 328 | 328 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 329 | - /** |
|
| 330 | - * Return if an invoice can be deleted |
|
| 331 | - * Rule is: |
|
| 332 | - * If invoice is draft and has a temporary ref -> yes (1) |
|
| 333 | - * If hidden option INVOICE_CAN_NEVER_BE_REMOVED is on -> no (0) |
|
| 334 | - * If invoice is dispatched in bookkeeping -> no (-1) |
|
| 335 | - * If invoice has a definitive ref, is not last and INVOICE_CAN_ALWAYS_BE_REMOVED off -> no (-2) |
|
| 336 | - * If invoice not last in a cycle -> no (-3) |
|
| 337 | - * If there is payment -> no (-4) |
|
| 338 | - * Otherwise -> yes (2) |
|
| 339 | - * |
|
| 340 | - * @return int <=0 if no, >0 if yes |
|
| 341 | - */ |
|
| 342 | - function is_erasable() |
|
| 343 | - { |
|
| 329 | + /** |
|
| 330 | + * Return if an invoice can be deleted |
|
| 331 | + * Rule is: |
|
| 332 | + * If invoice is draft and has a temporary ref -> yes (1) |
|
| 333 | + * If hidden option INVOICE_CAN_NEVER_BE_REMOVED is on -> no (0) |
|
| 334 | + * If invoice is dispatched in bookkeeping -> no (-1) |
|
| 335 | + * If invoice has a definitive ref, is not last and INVOICE_CAN_ALWAYS_BE_REMOVED off -> no (-2) |
|
| 336 | + * If invoice not last in a cycle -> no (-3) |
|
| 337 | + * If there is payment -> no (-4) |
|
| 338 | + * Otherwise -> yes (2) |
|
| 339 | + * |
|
| 340 | + * @return int <=0 if no, >0 if yes |
|
| 341 | + */ |
|
| 342 | + function is_erasable() |
|
| 343 | + { |
|
| 344 | 344 | // phpcs:enable |
| 345 | - global $conf; |
|
| 346 | - |
|
| 347 | - // We check if invoice is a temporary number (PROVxxxx) |
|
| 348 | - $tmppart = substr($this->ref, 1, 4); |
|
| 349 | - |
|
| 350 | - if ($this->statut == self::STATUS_DRAFT && $tmppart === 'PROV') // If draft invoice and ref not yet defined |
|
| 351 | - { |
|
| 352 | - return 1; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - if (! empty($conf->global->INVOICE_CAN_NEVER_BE_REMOVED)) return 0; |
|
| 356 | - |
|
| 357 | - // If not a draft invoice and not temporary invoice |
|
| 358 | - if ($tmppart !== 'PROV') |
|
| 359 | - { |
|
| 360 | - $ventilExportCompta = $this->getVentilExportCompta(); |
|
| 361 | - if ($ventilExportCompta != 0) return -1; |
|
| 362 | - |
|
| 363 | - // Get last number of validated invoice |
|
| 364 | - if ($this->element != 'invoice_supplier') |
|
| 365 | - { |
|
| 366 | - if (empty($this->thirdparty)) $this->fetch_thirdparty(); // We need to have this->thirdparty defined, in case of numbering rule use tags that depend on thirdparty (like {t} tag). |
|
| 367 | - $maxref = $this->getNextNumRef($this->thirdparty,'last'); |
|
| 368 | - |
|
| 369 | - // If there is no invoice into the reset range and not already dispatched, we can delete |
|
| 370 | - // If invoice to delete is last one and not already dispatched, we can delete |
|
| 371 | - if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $maxref != '' && $maxref != $this->ref) return -2; |
|
| 372 | - |
|
| 373 | - // TODO If there is payment in bookkeeping, check payment is not dispatched in accounting |
|
| 374 | - // ... |
|
| 375 | - |
|
| 376 | - if ($this->situation_cycle_ref && method_exists($this, 'is_last_in_cycle')) |
|
| 377 | - { |
|
| 378 | - $last = $this->is_last_in_cycle(); |
|
| 379 | - if (! $last) return -3; |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - // Test if there is at least one payment. If yes, refuse to delete. |
|
| 385 | - if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $this->getSommePaiement() > 0) return -4; |
|
| 386 | - |
|
| 387 | - return 2; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Return if an invoice was dispatched into bookkeeping |
|
| 392 | - * |
|
| 393 | - * @return int <0 if KO, 0=no, 1=yes |
|
| 394 | - */ |
|
| 395 | - public function getVentilExportCompta() |
|
| 396 | - { |
|
| 397 | - $alreadydispatched = 0; |
|
| 398 | - |
|
| 399 | - $type = 'customer_invoice'; |
|
| 400 | - if ($this->element == 'invoice_supplier') $type = 'supplier_invoice'; |
|
| 401 | - |
|
| 402 | - $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$type."' AND ab.fk_doc = ".$this->id; |
|
| 403 | - $resql = $this->db->query($sql); |
|
| 404 | - if ($resql) |
|
| 405 | - { |
|
| 406 | - $obj = $this->db->fetch_object($resql); |
|
| 407 | - if ($obj) |
|
| 408 | - { |
|
| 409 | - $alreadydispatched = $obj->nb; |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - else |
|
| 413 | - { |
|
| 414 | - $this->error = $this->db->lasterror(); |
|
| 415 | - return -1; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - if ($alreadydispatched) |
|
| 419 | - { |
|
| 420 | - return 1; |
|
| 421 | - } |
|
| 422 | - return 0; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Return label of type of invoice |
|
| 428 | - * |
|
| 429 | - * @return string Label of type of invoice |
|
| 430 | - */ |
|
| 431 | - function getLibType() |
|
| 432 | - { |
|
| 433 | - global $langs; |
|
| 345 | + global $conf; |
|
| 346 | + |
|
| 347 | + // We check if invoice is a temporary number (PROVxxxx) |
|
| 348 | + $tmppart = substr($this->ref, 1, 4); |
|
| 349 | + |
|
| 350 | + if ($this->statut == self::STATUS_DRAFT && $tmppart === 'PROV') // If draft invoice and ref not yet defined |
|
| 351 | + { |
|
| 352 | + return 1; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + if (! empty($conf->global->INVOICE_CAN_NEVER_BE_REMOVED)) return 0; |
|
| 356 | + |
|
| 357 | + // If not a draft invoice and not temporary invoice |
|
| 358 | + if ($tmppart !== 'PROV') |
|
| 359 | + { |
|
| 360 | + $ventilExportCompta = $this->getVentilExportCompta(); |
|
| 361 | + if ($ventilExportCompta != 0) return -1; |
|
| 362 | + |
|
| 363 | + // Get last number of validated invoice |
|
| 364 | + if ($this->element != 'invoice_supplier') |
|
| 365 | + { |
|
| 366 | + if (empty($this->thirdparty)) $this->fetch_thirdparty(); // We need to have this->thirdparty defined, in case of numbering rule use tags that depend on thirdparty (like {t} tag). |
|
| 367 | + $maxref = $this->getNextNumRef($this->thirdparty,'last'); |
|
| 368 | + |
|
| 369 | + // If there is no invoice into the reset range and not already dispatched, we can delete |
|
| 370 | + // If invoice to delete is last one and not already dispatched, we can delete |
|
| 371 | + if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $maxref != '' && $maxref != $this->ref) return -2; |
|
| 372 | + |
|
| 373 | + // TODO If there is payment in bookkeeping, check payment is not dispatched in accounting |
|
| 374 | + // ... |
|
| 375 | + |
|
| 376 | + if ($this->situation_cycle_ref && method_exists($this, 'is_last_in_cycle')) |
|
| 377 | + { |
|
| 378 | + $last = $this->is_last_in_cycle(); |
|
| 379 | + if (! $last) return -3; |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + // Test if there is at least one payment. If yes, refuse to delete. |
|
| 385 | + if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $this->getSommePaiement() > 0) return -4; |
|
| 386 | + |
|
| 387 | + return 2; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Return if an invoice was dispatched into bookkeeping |
|
| 392 | + * |
|
| 393 | + * @return int <0 if KO, 0=no, 1=yes |
|
| 394 | + */ |
|
| 395 | + public function getVentilExportCompta() |
|
| 396 | + { |
|
| 397 | + $alreadydispatched = 0; |
|
| 398 | + |
|
| 399 | + $type = 'customer_invoice'; |
|
| 400 | + if ($this->element == 'invoice_supplier') $type = 'supplier_invoice'; |
|
| 401 | + |
|
| 402 | + $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$type."' AND ab.fk_doc = ".$this->id; |
|
| 403 | + $resql = $this->db->query($sql); |
|
| 404 | + if ($resql) |
|
| 405 | + { |
|
| 406 | + $obj = $this->db->fetch_object($resql); |
|
| 407 | + if ($obj) |
|
| 408 | + { |
|
| 409 | + $alreadydispatched = $obj->nb; |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + else |
|
| 413 | + { |
|
| 414 | + $this->error = $this->db->lasterror(); |
|
| 415 | + return -1; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + if ($alreadydispatched) |
|
| 419 | + { |
|
| 420 | + return 1; |
|
| 421 | + } |
|
| 422 | + return 0; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Return label of type of invoice |
|
| 428 | + * |
|
| 429 | + * @return string Label of type of invoice |
|
| 430 | + */ |
|
| 431 | + function getLibType() |
|
| 432 | + { |
|
| 433 | + global $langs; |
|
| 434 | 434 | if ($this->type == CommonInvoice::TYPE_STANDARD) return $langs->trans("InvoiceStandard"); |
| 435 | 435 | elseif ($this->type == CommonInvoice::TYPE_REPLACEMENT) return $langs->trans("InvoiceReplacement"); |
| 436 | 436 | elseif ($this->type == CommonInvoice::TYPE_CREDIT_NOTE) return $langs->trans("InvoiceAvoir"); |
| 437 | 437 | elseif ($this->type == CommonInvoice::TYPE_DEPOSIT) return $langs->trans("InvoiceDeposit"); |
| 438 | 438 | elseif ($this->type == CommonInvoice::TYPE_PROFORMA) return $langs->trans("InvoiceProForma"); // Not used. |
| 439 | 439 | elseif ($this->type == CommonInvoice::TYPE_SITUATION) return $langs->trans("InvoiceSituation"); |
| 440 | - return $langs->trans("Unknown"); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Return label of object status |
|
| 445 | - * |
|
| 446 | - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto |
|
| 447 | - * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) |
|
| 448 | - * @return string Label of status |
|
| 449 | - */ |
|
| 450 | - function getLibStatut($mode=0, $alreadypaid=-1) |
|
| 451 | - { |
|
| 452 | - return $this->LibStatut($this->paye, $this->statut, $mode, $alreadypaid, $this->type); |
|
| 453 | - } |
|
| 440 | + return $langs->trans("Unknown"); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Return label of object status |
|
| 445 | + * |
|
| 446 | + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto |
|
| 447 | + * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) |
|
| 448 | + * @return string Label of status |
|
| 449 | + */ |
|
| 450 | + function getLibStatut($mode=0, $alreadypaid=-1) |
|
| 451 | + { |
|
| 452 | + return $this->LibStatut($this->paye, $this->statut, $mode, $alreadypaid, $this->type); |
|
| 453 | + } |
|
| 454 | 454 | |
| 455 | 455 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 456 | - /** |
|
| 457 | - * Return label of a status |
|
| 458 | - * |
|
| 459 | - * @param int $paye Status field paye |
|
| 460 | - * @param int $status Id status |
|
| 461 | - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=long label + picto |
|
| 462 | - * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, -1 otherwise) |
|
| 463 | - * @param int $type Type invoice |
|
| 464 | - * @return string Label of status |
|
| 465 | - */ |
|
| 466 | - function LibStatut($paye, $status, $mode=0, $alreadypaid=-1, $type=0) |
|
| 467 | - { |
|
| 456 | + /** |
|
| 457 | + * Return label of a status |
|
| 458 | + * |
|
| 459 | + * @param int $paye Status field paye |
|
| 460 | + * @param int $status Id status |
|
| 461 | + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=long label + picto |
|
| 462 | + * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, -1 otherwise) |
|
| 463 | + * @param int $type Type invoice |
|
| 464 | + * @return string Label of status |
|
| 465 | + */ |
|
| 466 | + function LibStatut($paye, $status, $mode=0, $alreadypaid=-1, $type=0) |
|
| 467 | + { |
|
| 468 | 468 | // phpcs:enable |
| 469 | - global $langs; |
|
| 470 | - $langs->load('bills'); |
|
| 471 | - |
|
| 472 | - //print "$paye,$status,$mode,$alreadypaid,$type"; |
|
| 473 | - if ($mode == 0) |
|
| 474 | - { |
|
| 475 | - $prefix=''; |
|
| 476 | - if (! $paye) |
|
| 477 | - { |
|
| 478 | - if ($status == 0) return $langs->trans('Bill'.$prefix.'StatusDraft'); |
|
| 479 | - elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusClosedUnpaid'); |
|
| 480 | - elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); |
|
| 481 | - elseif ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid'); |
|
| 482 | - else return $langs->trans('Bill'.$prefix.'StatusStarted'); |
|
| 483 | - } |
|
| 484 | - else |
|
| 485 | - { |
|
| 486 | - if ($type == self::TYPE_CREDIT_NOTE) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); // credit note |
|
| 487 | - elseif ($type == self::TYPE_DEPOSIT) return $langs->trans('Bill'.$prefix.'StatusConverted'); // deposit invoice |
|
| 488 | - else return $langs->trans('Bill'.$prefix.'StatusPaid'); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - elseif ($mode == 1) |
|
| 492 | - { |
|
| 493 | - $prefix='Short'; |
|
| 494 | - if (! $paye) |
|
| 495 | - { |
|
| 496 | - if ($status == 0) return $langs->trans('Bill'.$prefix.'StatusDraft'); |
|
| 497 | - elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled'); |
|
| 498 | - elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); |
|
| 499 | - elseif ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid'); |
|
| 500 | - else return $langs->trans('Bill'.$prefix.'StatusStarted'); |
|
| 501 | - } |
|
| 502 | - else |
|
| 503 | - { |
|
| 504 | - if ($type == self::TYPE_CREDIT_NOTE) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); |
|
| 505 | - elseif ($type == self::TYPE_DEPOSIT) return $langs->trans('Bill'.$prefix.'StatusConverted'); |
|
| 506 | - else return $langs->trans('Bill'.$prefix.'StatusPaid'); |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - elseif ($mode == 2) |
|
| 510 | - { |
|
| 511 | - $prefix='Short'; |
|
| 512 | - if (! $paye) |
|
| 513 | - { |
|
| 514 | - if ($status == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('Bill'.$prefix.'StatusDraft'); |
|
| 515 | - elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return img_picto($langs->trans('StatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled'); |
|
| 516 | - elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut9').' '.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); |
|
| 517 | - elseif ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1').' '.$langs->trans('Bill'.$prefix.'StatusNotPaid'); |
|
| 518 | - else return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('Bill'.$prefix.'StatusStarted'); |
|
| 519 | - } |
|
| 520 | - else |
|
| 521 | - { |
|
| 522 | - if ($type == self::TYPE_CREDIT_NOTE) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); |
|
| 523 | - elseif ($type == self::TYPE_DEPOSIT) return img_picto($langs->trans('BillStatusConverted'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusConverted'); |
|
| 524 | - else return img_picto($langs->trans('BillStatusPaid'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusPaid'); |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - elseif ($mode == 3) |
|
| 528 | - { |
|
| 529 | - $prefix='Short'; |
|
| 530 | - if (! $paye) |
|
| 531 | - { |
|
| 532 | - if ($status == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0'); |
|
| 533 | - elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5'); |
|
| 534 | - elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut9'); |
|
| 535 | - elseif ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1'); |
|
| 536 | - else return img_picto($langs->trans('BillStatusStarted'),'statut3'); |
|
| 537 | - } |
|
| 538 | - else |
|
| 539 | - { |
|
| 540 | - if ($type == self::TYPE_CREDIT_NOTE) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6'); |
|
| 541 | - elseif ($type == self::TYPE_DEPOSIT) return img_picto($langs->trans('BillStatusConverted'),'statut6'); |
|
| 542 | - else return img_picto($langs->trans('BillStatusPaid'),'statut6'); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - elseif ($mode == 4) |
|
| 546 | - { |
|
| 547 | - $prefix=''; |
|
| 548 | - if (! $paye) |
|
| 549 | - { |
|
| 550 | - if ($status == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('BillStatusDraft'); |
|
| 551 | - elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled'); |
|
| 552 | - elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut9').' '.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); |
|
| 553 | - elseif ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1').' '.$langs->trans('BillStatusNotPaid'); |
|
| 554 | - else return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('BillStatusStarted'); |
|
| 555 | - } |
|
| 556 | - else |
|
| 557 | - { |
|
| 558 | - if ($type == self::TYPE_CREDIT_NOTE) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6').' '.$langs->trans('BillStatusPaidBackOrConverted'); |
|
| 559 | - elseif ($type == self::TYPE_DEPOSIT) return img_picto($langs->trans('BillStatusConverted'),'statut6').' '.$langs->trans('BillStatusConverted'); |
|
| 560 | - else return img_picto($langs->trans('BillStatusPaid'),'statut6').' '.$langs->trans('BillStatusPaid'); |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - elseif ($mode == 5 || $mode == 6) |
|
| 564 | - { |
|
| 565 | - $prefix=''; |
|
| 566 | - if ($mode == 5) $prefix='Short'; |
|
| 567 | - if (! $paye) |
|
| 568 | - { |
|
| 569 | - if ($status == 0) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusDraft').' </span>'.img_picto($langs->trans('BillStatusDraft'),'statut0'); |
|
| 570 | - elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusCanceled').' </span>'.img_picto($langs->trans('BillStatusCanceled'),'statut5'); |
|
| 571 | - elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially').' </span>'.img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut9'); |
|
| 572 | - elseif ($alreadypaid <= 0) |
|
| 573 | - { |
|
| 574 | - if ($type == self::TYPE_CREDIT_NOTE) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusNotRefunded').' </span>'.img_picto($langs->trans('StatusNotRefunded'),'statut1'); |
|
| 575 | - return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusNotPaid').' </span>'.img_picto($langs->trans('BillStatusNotPaid'),'statut1'); |
|
| 576 | - } |
|
| 577 | - else return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusStarted').' </span>'.img_picto($langs->trans('BillStatusStarted'),'statut3'); |
|
| 578 | - } |
|
| 579 | - else |
|
| 580 | - { |
|
| 581 | - if ($type == self::TYPE_CREDIT_NOTE) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted').' </span>'.img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6'); |
|
| 582 | - elseif ($type == self::TYPE_DEPOSIT) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusConverted').' </span>'.img_picto($langs->trans('BillStatusConverted'),'statut6'); |
|
| 583 | - else return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusPaid').' </span>'.img_picto($langs->trans('BillStatusPaid'),'statut6'); |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - } |
|
| 469 | + global $langs; |
|
| 470 | + $langs->load('bills'); |
|
| 471 | + |
|
| 472 | + //print "$paye,$status,$mode,$alreadypaid,$type"; |
|
| 473 | + if ($mode == 0) |
|
| 474 | + { |
|
| 475 | + $prefix=''; |
|
| 476 | + if (! $paye) |
|
| 477 | + { |
|
| 478 | + if ($status == 0) return $langs->trans('Bill'.$prefix.'StatusDraft'); |
|
| 479 | + elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusClosedUnpaid'); |
|
| 480 | + elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); |
|
| 481 | + elseif ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid'); |
|
| 482 | + else return $langs->trans('Bill'.$prefix.'StatusStarted'); |
|
| 483 | + } |
|
| 484 | + else |
|
| 485 | + { |
|
| 486 | + if ($type == self::TYPE_CREDIT_NOTE) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); // credit note |
|
| 487 | + elseif ($type == self::TYPE_DEPOSIT) return $langs->trans('Bill'.$prefix.'StatusConverted'); // deposit invoice |
|
| 488 | + else return $langs->trans('Bill'.$prefix.'StatusPaid'); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + elseif ($mode == 1) |
|
| 492 | + { |
|
| 493 | + $prefix='Short'; |
|
| 494 | + if (! $paye) |
|
| 495 | + { |
|
| 496 | + if ($status == 0) return $langs->trans('Bill'.$prefix.'StatusDraft'); |
|
| 497 | + elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusCanceled'); |
|
| 498 | + elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return $langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); |
|
| 499 | + elseif ($alreadypaid <= 0) return $langs->trans('Bill'.$prefix.'StatusNotPaid'); |
|
| 500 | + else return $langs->trans('Bill'.$prefix.'StatusStarted'); |
|
| 501 | + } |
|
| 502 | + else |
|
| 503 | + { |
|
| 504 | + if ($type == self::TYPE_CREDIT_NOTE) return $langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); |
|
| 505 | + elseif ($type == self::TYPE_DEPOSIT) return $langs->trans('Bill'.$prefix.'StatusConverted'); |
|
| 506 | + else return $langs->trans('Bill'.$prefix.'StatusPaid'); |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + elseif ($mode == 2) |
|
| 510 | + { |
|
| 511 | + $prefix='Short'; |
|
| 512 | + if (! $paye) |
|
| 513 | + { |
|
| 514 | + if ($status == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('Bill'.$prefix.'StatusDraft'); |
|
| 515 | + elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return img_picto($langs->trans('StatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled'); |
|
| 516 | + elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut9').' '.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); |
|
| 517 | + elseif ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1').' '.$langs->trans('Bill'.$prefix.'StatusNotPaid'); |
|
| 518 | + else return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('Bill'.$prefix.'StatusStarted'); |
|
| 519 | + } |
|
| 520 | + else |
|
| 521 | + { |
|
| 522 | + if ($type == self::TYPE_CREDIT_NOTE) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted'); |
|
| 523 | + elseif ($type == self::TYPE_DEPOSIT) return img_picto($langs->trans('BillStatusConverted'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusConverted'); |
|
| 524 | + else return img_picto($langs->trans('BillStatusPaid'),'statut6').' '.$langs->trans('Bill'.$prefix.'StatusPaid'); |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + elseif ($mode == 3) |
|
| 528 | + { |
|
| 529 | + $prefix='Short'; |
|
| 530 | + if (! $paye) |
|
| 531 | + { |
|
| 532 | + if ($status == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0'); |
|
| 533 | + elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5'); |
|
| 534 | + elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut9'); |
|
| 535 | + elseif ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1'); |
|
| 536 | + else return img_picto($langs->trans('BillStatusStarted'),'statut3'); |
|
| 537 | + } |
|
| 538 | + else |
|
| 539 | + { |
|
| 540 | + if ($type == self::TYPE_CREDIT_NOTE) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6'); |
|
| 541 | + elseif ($type == self::TYPE_DEPOSIT) return img_picto($langs->trans('BillStatusConverted'),'statut6'); |
|
| 542 | + else return img_picto($langs->trans('BillStatusPaid'),'statut6'); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + elseif ($mode == 4) |
|
| 546 | + { |
|
| 547 | + $prefix=''; |
|
| 548 | + if (! $paye) |
|
| 549 | + { |
|
| 550 | + if ($status == 0) return img_picto($langs->trans('BillStatusDraft'),'statut0').' '.$langs->trans('BillStatusDraft'); |
|
| 551 | + elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return img_picto($langs->trans('BillStatusCanceled'),'statut5').' '.$langs->trans('Bill'.$prefix.'StatusCanceled'); |
|
| 552 | + elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut9').' '.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially'); |
|
| 553 | + elseif ($alreadypaid <= 0) return img_picto($langs->trans('BillStatusNotPaid'),'statut1').' '.$langs->trans('BillStatusNotPaid'); |
|
| 554 | + else return img_picto($langs->trans('BillStatusStarted'),'statut3').' '.$langs->trans('BillStatusStarted'); |
|
| 555 | + } |
|
| 556 | + else |
|
| 557 | + { |
|
| 558 | + if ($type == self::TYPE_CREDIT_NOTE) return img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6').' '.$langs->trans('BillStatusPaidBackOrConverted'); |
|
| 559 | + elseif ($type == self::TYPE_DEPOSIT) return img_picto($langs->trans('BillStatusConverted'),'statut6').' '.$langs->trans('BillStatusConverted'); |
|
| 560 | + else return img_picto($langs->trans('BillStatusPaid'),'statut6').' '.$langs->trans('BillStatusPaid'); |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + elseif ($mode == 5 || $mode == 6) |
|
| 564 | + { |
|
| 565 | + $prefix=''; |
|
| 566 | + if ($mode == 5) $prefix='Short'; |
|
| 567 | + if (! $paye) |
|
| 568 | + { |
|
| 569 | + if ($status == 0) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusDraft').' </span>'.img_picto($langs->trans('BillStatusDraft'),'statut0'); |
|
| 570 | + elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusCanceled').' </span>'.img_picto($langs->trans('BillStatusCanceled'),'statut5'); |
|
| 571 | + elseif (($status == 3 || $status == 2) && $alreadypaid > 0) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusClosedPaidPartially').' </span>'.img_picto($langs->trans('BillStatusClosedPaidPartially'),'statut9'); |
|
| 572 | + elseif ($alreadypaid <= 0) |
|
| 573 | + { |
|
| 574 | + if ($type == self::TYPE_CREDIT_NOTE) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusNotRefunded').' </span>'.img_picto($langs->trans('StatusNotRefunded'),'statut1'); |
|
| 575 | + return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusNotPaid').' </span>'.img_picto($langs->trans('BillStatusNotPaid'),'statut1'); |
|
| 576 | + } |
|
| 577 | + else return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusStarted').' </span>'.img_picto($langs->trans('BillStatusStarted'),'statut3'); |
|
| 578 | + } |
|
| 579 | + else |
|
| 580 | + { |
|
| 581 | + if ($type == self::TYPE_CREDIT_NOTE) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusPaidBackOrConverted').' </span>'.img_picto($langs->trans('BillStatusPaidBackOrConverted'),'statut6'); |
|
| 582 | + elseif ($type == self::TYPE_DEPOSIT) return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusConverted').' </span>'.img_picto($langs->trans('BillStatusConverted'),'statut6'); |
|
| 583 | + else return '<span class="xhideonsmartphone">'.$langs->trans('Bill'.$prefix.'StatusPaid').' </span>'.img_picto($langs->trans('BillStatusPaid'),'statut6'); |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | 587 | |
| 588 | 588 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 589 | - /** |
|
| 590 | - * Renvoi une date limite de reglement de facture en fonction des |
|
| 591 | - * conditions de reglements de la facture et date de facturation. |
|
| 592 | - * |
|
| 593 | - * @param integer $cond_reglement Condition of payment (code or id) to use. If 0, we use current condition. |
|
| 594 | - * @return date Date limite de reglement si ok, <0 si ko |
|
| 595 | - */ |
|
| 596 | - function calculate_date_lim_reglement($cond_reglement=0) |
|
| 597 | - { |
|
| 589 | + /** |
|
| 590 | + * Renvoi une date limite de reglement de facture en fonction des |
|
| 591 | + * conditions de reglements de la facture et date de facturation. |
|
| 592 | + * |
|
| 593 | + * @param integer $cond_reglement Condition of payment (code or id) to use. If 0, we use current condition. |
|
| 594 | + * @return date Date limite de reglement si ok, <0 si ko |
|
| 595 | + */ |
|
| 596 | + function calculate_date_lim_reglement($cond_reglement=0) |
|
| 597 | + { |
|
| 598 | 598 | // phpcs:enable |
| 599 | - if (! $cond_reglement) $cond_reglement=$this->cond_reglement_code; |
|
| 600 | - if (! $cond_reglement) $cond_reglement=$this->cond_reglement_id; |
|
| 599 | + if (! $cond_reglement) $cond_reglement=$this->cond_reglement_code; |
|
| 600 | + if (! $cond_reglement) $cond_reglement=$this->cond_reglement_id; |
|
| 601 | 601 | |
| 602 | - $cdr_nbjour=0; |
|
| 602 | + $cdr_nbjour=0; |
|
| 603 | 603 | $cdr_type=0; |
| 604 | 604 | $cdr_decalage=0; |
| 605 | 605 | |
| 606 | - $sqltemp = 'SELECT c.type_cdr, c.nbjour, c.decalage'; |
|
| 607 | - $sqltemp.= ' FROM '.MAIN_DB_PREFIX.'c_payment_term as c'; |
|
| 608 | - if (is_numeric($cond_reglement)) $sqltemp.= " WHERE c.rowid=".$cond_reglement; |
|
| 609 | - else { |
|
| 610 | - $sqltemp.= " WHERE c.entity IN (".getEntity('c_payment_term').")"; |
|
| 611 | - $sqltemp.= " AND c.code='".$this->db->escape($cond_reglement)."'"; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - dol_syslog(get_class($this).'::calculate_date_lim_reglement', LOG_DEBUG); |
|
| 615 | - $resqltemp=$this->db->query($sqltemp); |
|
| 616 | - if ($resqltemp) |
|
| 617 | - { |
|
| 618 | - if ($this->db->num_rows($resqltemp)) |
|
| 619 | - { |
|
| 620 | - $obj = $this->db->fetch_object($resqltemp); |
|
| 621 | - $cdr_nbjour = $obj->nbjour; |
|
| 622 | - $cdr_type = $obj->type_cdr; |
|
| 623 | - $cdr_decalage = $obj->decalage; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - else |
|
| 627 | - { |
|
| 628 | - $this->error=$this->db->error(); |
|
| 629 | - return -1; |
|
| 630 | - } |
|
| 631 | - $this->db->free($resqltemp); |
|
| 632 | - |
|
| 633 | - /* Definition de la date limite */ |
|
| 634 | - |
|
| 635 | - // 0 : ajout du nombre de jours |
|
| 636 | - if ($cdr_type == 0) |
|
| 637 | - { |
|
| 638 | - $datelim = $this->date + ($cdr_nbjour * 3600 * 24); |
|
| 639 | - |
|
| 640 | - $datelim += ($cdr_decalage * 3600 * 24); |
|
| 641 | - } |
|
| 642 | - // 1 : application de la regle "fin de mois" |
|
| 643 | - elseif ($cdr_type == 1) |
|
| 644 | - { |
|
| 645 | - $datelim = $this->date + ($cdr_nbjour * 3600 * 24); |
|
| 646 | - |
|
| 647 | - $mois=date('m', $datelim); |
|
| 648 | - $annee=date('Y', $datelim); |
|
| 649 | - if ($mois == 12) |
|
| 650 | - { |
|
| 651 | - $mois = 1; |
|
| 652 | - $annee += 1; |
|
| 653 | - } |
|
| 654 | - else |
|
| 655 | - { |
|
| 656 | - $mois += 1; |
|
| 657 | - } |
|
| 658 | - // On se deplace au debut du mois suivant, et on retire un jour |
|
| 659 | - $datelim=dol_mktime(12,0,0,$mois,1,$annee); |
|
| 660 | - $datelim -= (3600 * 24); |
|
| 661 | - |
|
| 662 | - $datelim += ($cdr_decalage * 3600 * 24); |
|
| 663 | - } |
|
| 664 | - // 2 : application de la règle, le N du mois courant ou suivant |
|
| 665 | - elseif ($cdr_type == 2 && !empty($cdr_decalage)) |
|
| 666 | - { |
|
| 667 | - $datelim = $this->date + ($cdr_nbjour * 3600 * 24); |
|
| 668 | - |
|
| 669 | - $date_piece = dol_mktime(0, 0, 0, date('m', $datelim),date('d', $datelim),date('Y', $datelim)); // Sans les heures minutes et secondes |
|
| 670 | - $date_lim_current = dol_mktime(0, 0, 0, date('m', $datelim), $cdr_decalage, date('Y', $datelim)); // Sans les heures minutes et secondes |
|
| 671 | - $date_lim_next = dol_time_plus_duree($date_lim_current, 1, 'm'); // Add 1 month |
|
| 672 | - |
|
| 673 | - $diff = $date_piece - $date_lim_current; |
|
| 674 | - |
|
| 675 | - if ($diff < 0) $datelim = $date_lim_current; |
|
| 676 | - else $datelim = $date_lim_next; |
|
| 677 | - } |
|
| 678 | - else return 'Bad value for type_cdr in database for record cond_reglement = '.$cond_reglement; |
|
| 679 | - |
|
| 680 | - return $datelim; |
|
| 681 | - } |
|
| 606 | + $sqltemp = 'SELECT c.type_cdr, c.nbjour, c.decalage'; |
|
| 607 | + $sqltemp.= ' FROM '.MAIN_DB_PREFIX.'c_payment_term as c'; |
|
| 608 | + if (is_numeric($cond_reglement)) $sqltemp.= " WHERE c.rowid=".$cond_reglement; |
|
| 609 | + else { |
|
| 610 | + $sqltemp.= " WHERE c.entity IN (".getEntity('c_payment_term').")"; |
|
| 611 | + $sqltemp.= " AND c.code='".$this->db->escape($cond_reglement)."'"; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + dol_syslog(get_class($this).'::calculate_date_lim_reglement', LOG_DEBUG); |
|
| 615 | + $resqltemp=$this->db->query($sqltemp); |
|
| 616 | + if ($resqltemp) |
|
| 617 | + { |
|
| 618 | + if ($this->db->num_rows($resqltemp)) |
|
| 619 | + { |
|
| 620 | + $obj = $this->db->fetch_object($resqltemp); |
|
| 621 | + $cdr_nbjour = $obj->nbjour; |
|
| 622 | + $cdr_type = $obj->type_cdr; |
|
| 623 | + $cdr_decalage = $obj->decalage; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + else |
|
| 627 | + { |
|
| 628 | + $this->error=$this->db->error(); |
|
| 629 | + return -1; |
|
| 630 | + } |
|
| 631 | + $this->db->free($resqltemp); |
|
| 632 | + |
|
| 633 | + /* Definition de la date limite */ |
|
| 634 | + |
|
| 635 | + // 0 : ajout du nombre de jours |
|
| 636 | + if ($cdr_type == 0) |
|
| 637 | + { |
|
| 638 | + $datelim = $this->date + ($cdr_nbjour * 3600 * 24); |
|
| 639 | + |
|
| 640 | + $datelim += ($cdr_decalage * 3600 * 24); |
|
| 641 | + } |
|
| 642 | + // 1 : application de la regle "fin de mois" |
|
| 643 | + elseif ($cdr_type == 1) |
|
| 644 | + { |
|
| 645 | + $datelim = $this->date + ($cdr_nbjour * 3600 * 24); |
|
| 646 | + |
|
| 647 | + $mois=date('m', $datelim); |
|
| 648 | + $annee=date('Y', $datelim); |
|
| 649 | + if ($mois == 12) |
|
| 650 | + { |
|
| 651 | + $mois = 1; |
|
| 652 | + $annee += 1; |
|
| 653 | + } |
|
| 654 | + else |
|
| 655 | + { |
|
| 656 | + $mois += 1; |
|
| 657 | + } |
|
| 658 | + // On se deplace au debut du mois suivant, et on retire un jour |
|
| 659 | + $datelim=dol_mktime(12,0,0,$mois,1,$annee); |
|
| 660 | + $datelim -= (3600 * 24); |
|
| 661 | + |
|
| 662 | + $datelim += ($cdr_decalage * 3600 * 24); |
|
| 663 | + } |
|
| 664 | + // 2 : application de la règle, le N du mois courant ou suivant |
|
| 665 | + elseif ($cdr_type == 2 && !empty($cdr_decalage)) |
|
| 666 | + { |
|
| 667 | + $datelim = $this->date + ($cdr_nbjour * 3600 * 24); |
|
| 668 | + |
|
| 669 | + $date_piece = dol_mktime(0, 0, 0, date('m', $datelim),date('d', $datelim),date('Y', $datelim)); // Sans les heures minutes et secondes |
|
| 670 | + $date_lim_current = dol_mktime(0, 0, 0, date('m', $datelim), $cdr_decalage, date('Y', $datelim)); // Sans les heures minutes et secondes |
|
| 671 | + $date_lim_next = dol_time_plus_duree($date_lim_current, 1, 'm'); // Add 1 month |
|
| 672 | + |
|
| 673 | + $diff = $date_piece - $date_lim_current; |
|
| 674 | + |
|
| 675 | + if ($diff < 0) $datelim = $date_lim_current; |
|
| 676 | + else $datelim = $date_lim_next; |
|
| 677 | + } |
|
| 678 | + else return 'Bad value for type_cdr in database for record cond_reglement = '.$cond_reglement; |
|
| 679 | + |
|
| 680 | + return $datelim; |
|
| 681 | + } |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | |
@@ -690,105 +690,105 @@ discard block |
||
| 690 | 690 | */ |
| 691 | 691 | abstract class CommonInvoiceLine extends CommonObjectLine |
| 692 | 692 | { |
| 693 | - /** |
|
| 694 | - * Quantity |
|
| 695 | - * @var double |
|
| 696 | - */ |
|
| 697 | - public $qty; |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * Unit price before taxes |
|
| 701 | - * @var float |
|
| 702 | - */ |
|
| 703 | - public $subprice; |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * Type of the product. 0 for product 1 for service |
|
| 707 | - * @var int |
|
| 708 | - */ |
|
| 709 | - public $product_type = 0; |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Id of corresponding product |
|
| 713 | - * @var int |
|
| 714 | - */ |
|
| 715 | - public $fk_product; |
|
| 716 | - |
|
| 717 | - /** |
|
| 718 | - * VAT code |
|
| 719 | - * @var string |
|
| 720 | - */ |
|
| 721 | - public $vat_src_code; |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * VAT % |
|
| 725 | - * @var float |
|
| 726 | - */ |
|
| 727 | - public $tva_tx; |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * Local tax 1 % |
|
| 731 | - * @var float |
|
| 732 | - */ |
|
| 733 | - public $localtax1_tx; |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * Local tax 2 % |
|
| 737 | - * @var float |
|
| 738 | - */ |
|
| 739 | - public $localtax2_tx; |
|
| 740 | - |
|
| 741 | - /** |
|
| 742 | - * Percent of discount |
|
| 743 | - * @var float |
|
| 744 | - */ |
|
| 745 | - public $remise_percent; |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * Total amount before taxes |
|
| 749 | - * @var float |
|
| 750 | - */ |
|
| 751 | - public $total_ht; |
|
| 752 | - |
|
| 753 | - /** |
|
| 754 | - * Total VAT amount |
|
| 755 | - * @var float |
|
| 756 | - */ |
|
| 757 | - public $total_tva; |
|
| 758 | - |
|
| 759 | - /** |
|
| 760 | - * Total local tax 1 amount |
|
| 761 | - * @var float |
|
| 762 | - */ |
|
| 763 | - public $total_localtax1; |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Total local tax 2 amount |
|
| 767 | - * @var float |
|
| 768 | - */ |
|
| 769 | - public $total_localtax2; |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * Total amount with taxes |
|
| 773 | - * @var float |
|
| 774 | - */ |
|
| 775 | - public $total_ttc; |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * Liste d'options cumulables: |
|
| 779 | - * Bit 0: 0 si TVA normal - 1 si TVA NPR |
|
| 780 | - * Bit 1: 0 si ligne normal - 1 si bit discount (link to line into llx_remise_except) |
|
| 781 | - * @var int |
|
| 782 | - */ |
|
| 783 | - public $info_bits = 0; |
|
| 784 | - |
|
| 785 | - /** |
|
| 786 | - * Constructor |
|
| 787 | - * |
|
| 788 | - * @param DoliDB $db Database handler |
|
| 789 | - */ |
|
| 790 | - public function __construct(DoliDB $db) |
|
| 791 | - { |
|
| 792 | - $this->db = $db; |
|
| 793 | - } |
|
| 693 | + /** |
|
| 694 | + * Quantity |
|
| 695 | + * @var double |
|
| 696 | + */ |
|
| 697 | + public $qty; |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * Unit price before taxes |
|
| 701 | + * @var float |
|
| 702 | + */ |
|
| 703 | + public $subprice; |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * Type of the product. 0 for product 1 for service |
|
| 707 | + * @var int |
|
| 708 | + */ |
|
| 709 | + public $product_type = 0; |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Id of corresponding product |
|
| 713 | + * @var int |
|
| 714 | + */ |
|
| 715 | + public $fk_product; |
|
| 716 | + |
|
| 717 | + /** |
|
| 718 | + * VAT code |
|
| 719 | + * @var string |
|
| 720 | + */ |
|
| 721 | + public $vat_src_code; |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * VAT % |
|
| 725 | + * @var float |
|
| 726 | + */ |
|
| 727 | + public $tva_tx; |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * Local tax 1 % |
|
| 731 | + * @var float |
|
| 732 | + */ |
|
| 733 | + public $localtax1_tx; |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * Local tax 2 % |
|
| 737 | + * @var float |
|
| 738 | + */ |
|
| 739 | + public $localtax2_tx; |
|
| 740 | + |
|
| 741 | + /** |
|
| 742 | + * Percent of discount |
|
| 743 | + * @var float |
|
| 744 | + */ |
|
| 745 | + public $remise_percent; |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * Total amount before taxes |
|
| 749 | + * @var float |
|
| 750 | + */ |
|
| 751 | + public $total_ht; |
|
| 752 | + |
|
| 753 | + /** |
|
| 754 | + * Total VAT amount |
|
| 755 | + * @var float |
|
| 756 | + */ |
|
| 757 | + public $total_tva; |
|
| 758 | + |
|
| 759 | + /** |
|
| 760 | + * Total local tax 1 amount |
|
| 761 | + * @var float |
|
| 762 | + */ |
|
| 763 | + public $total_localtax1; |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Total local tax 2 amount |
|
| 767 | + * @var float |
|
| 768 | + */ |
|
| 769 | + public $total_localtax2; |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * Total amount with taxes |
|
| 773 | + * @var float |
|
| 774 | + */ |
|
| 775 | + public $total_ttc; |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * Liste d'options cumulables: |
|
| 779 | + * Bit 0: 0 si TVA normal - 1 si TVA NPR |
|
| 780 | + * Bit 1: 0 si ligne normal - 1 si bit discount (link to line into llx_remise_except) |
|
| 781 | + * @var int |
|
| 782 | + */ |
|
| 783 | + public $info_bits = 0; |
|
| 784 | + |
|
| 785 | + /** |
|
| 786 | + * Constructor |
|
| 787 | + * |
|
| 788 | + * @param DoliDB $db Database handler |
|
| 789 | + */ |
|
| 790 | + public function __construct(DoliDB $db) |
|
| 791 | + { |
|
| 792 | + $this->db = $db; |
|
| 793 | + } |
|
| 794 | 794 | } |
@@ -21,347 +21,347 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Comment extends CommonObject |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var string ID to identify managed object |
|
| 26 | - */ |
|
| 27 | - public $element='comment'; |
|
| 24 | + /** |
|
| 25 | + * @var string ID to identify managed object |
|
| 26 | + */ |
|
| 27 | + public $element='comment'; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var string Name of table without prefix where object is stored |
|
| 31 | - */ |
|
| 32 | - public $table_element='comment'; |
|
| 29 | + /** |
|
| 30 | + * @var string Name of table without prefix where object is stored |
|
| 31 | + */ |
|
| 32 | + public $table_element='comment'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var int Field with ID of parent key if this field has a parent |
|
| 36 | - */ |
|
| 37 | - public $fk_element =''; |
|
| 34 | + /** |
|
| 35 | + * @var int Field with ID of parent key if this field has a parent |
|
| 36 | + */ |
|
| 37 | + public $fk_element =''; |
|
| 38 | 38 | |
| 39 | - public $element_type; |
|
| 39 | + public $element_type; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var string description |
|
| 43 | - */ |
|
| 44 | - public $description; |
|
| 41 | + /** |
|
| 42 | + * @var string description |
|
| 43 | + */ |
|
| 44 | + public $description; |
|
| 45 | 45 | |
| 46 | - public $tms; |
|
| 46 | + public $tms; |
|
| 47 | 47 | |
| 48 | - public $datec; |
|
| 48 | + public $datec; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | + /** |
|
| 51 | 51 | * @var int ID |
| 52 | 52 | */ |
| 53 | - public $fk_user_author; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var int Entity |
|
| 57 | - */ |
|
| 58 | - public $entity; |
|
| 59 | - |
|
| 60 | - public $import_key; |
|
| 61 | - |
|
| 62 | - public $comments = array(); |
|
| 63 | - |
|
| 64 | - public $oldcopy; |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Constructor |
|
| 69 | - * |
|
| 70 | - * @param DoliDB $db Database handler |
|
| 71 | - */ |
|
| 72 | - function __construct($db) |
|
| 73 | - { |
|
| 74 | - $this->db = $db; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Create into database |
|
| 80 | - * |
|
| 81 | - * @param User $user User that create |
|
| 82 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 83 | - * @return int <0 if KO, Id of created object if OK |
|
| 84 | - */ |
|
| 85 | - function create($user, $notrigger=0) |
|
| 86 | - { |
|
| 87 | - global $conf, $langs; |
|
| 88 | - |
|
| 89 | - $error=0; |
|
| 90 | - |
|
| 91 | - // Insert request |
|
| 92 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."comment ("; |
|
| 93 | - $sql.= "description"; |
|
| 94 | - $sql.= ", datec"; |
|
| 95 | - $sql.= ", fk_element"; |
|
| 96 | - $sql.= ", element_type"; |
|
| 97 | - $sql.= ", fk_user_author"; |
|
| 98 | - $sql.= ", entity"; |
|
| 99 | - $sql.= ", import_key"; |
|
| 100 | - $sql.= ") VALUES ("; |
|
| 101 | - $sql.= "'".$this->db->escape($this->description)."'"; |
|
| 102 | - $sql.= ", ".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null'); |
|
| 103 | - $sql.= ", '".(isset($this->fk_element)?$this->fk_element:"null")."'"; |
|
| 104 | - $sql.= ", '".$this->db->escape($this->element_type)."'"; |
|
| 105 | - $sql.= ", '".(isset($this->fk_user_author)?$this->fk_user_author:"null")."'"; |
|
| 106 | - $sql.= ", ".(!empty($this->entity)?$this->entity:'1'); |
|
| 107 | - $sql.= ", ".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); |
|
| 108 | - $sql.= ")"; |
|
| 109 | - |
|
| 110 | - //var_dump($this->db); |
|
| 111 | - //echo $sql; |
|
| 112 | - |
|
| 113 | - $this->db->begin(); |
|
| 114 | - |
|
| 115 | - dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 116 | - $resql=$this->db->query($sql); |
|
| 117 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 118 | - |
|
| 119 | - if (! $error) |
|
| 120 | - { |
|
| 121 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_comment"); |
|
| 122 | - |
|
| 123 | - if (! $notrigger) |
|
| 124 | - { |
|
| 125 | - // Call trigger |
|
| 126 | - $result=$this->call_trigger('TASK_COMMENT_CREATE',$user); |
|
| 127 | - if ($result < 0) { $error++; } |
|
| 128 | - // End call triggers |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Commit or rollback |
|
| 133 | - if ($error) |
|
| 134 | - { |
|
| 135 | - foreach($this->errors as $errmsg) |
|
| 136 | - { |
|
| 137 | - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
| 138 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 139 | - } |
|
| 140 | - $this->db->rollback(); |
|
| 141 | - return -1*$error; |
|
| 142 | - } |
|
| 143 | - else |
|
| 144 | - { |
|
| 145 | - $this->db->commit(); |
|
| 146 | - return $this->id; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Load object in memory from database |
|
| 153 | - * |
|
| 154 | - * @param int $id Id object |
|
| 155 | - * @param int $ref ref object |
|
| 156 | - * @return int <0 if KO, 0 if not found, >0 if OK |
|
| 157 | - */ |
|
| 158 | - function fetch($id, $ref='') |
|
| 159 | - { |
|
| 160 | - global $langs; |
|
| 161 | - |
|
| 162 | - $sql = "SELECT"; |
|
| 163 | - $sql.= " c.rowid,"; |
|
| 164 | - $sql.= " c.description,"; |
|
| 165 | - $sql.= " c.datec,"; |
|
| 166 | - $sql.= " c.tms,"; |
|
| 167 | - $sql.= " c.fk_element,"; |
|
| 168 | - $sql.= " c.element_type,"; |
|
| 169 | - $sql.= " c.fk_user_author,"; |
|
| 170 | - $sql.= " c.entity,"; |
|
| 171 | - $sql.= " c.import_key"; |
|
| 172 | - $sql.= " FROM ".MAIN_DB_PREFIX."comment as c"; |
|
| 173 | - $sql.= " WHERE c.rowid = ".$id; |
|
| 174 | - |
|
| 175 | - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
| 176 | - $resql=$this->db->query($sql); |
|
| 177 | - if ($resql) |
|
| 178 | - { |
|
| 179 | - $num_rows = $this->db->num_rows($resql); |
|
| 180 | - |
|
| 181 | - if ($num_rows) |
|
| 182 | - { |
|
| 183 | - $obj = $this->db->fetch_object($resql); |
|
| 184 | - |
|
| 185 | - $this->id = $obj->rowid; |
|
| 186 | - $this->description = $obj->description; |
|
| 187 | - $this->element_type = $obj->element_type; |
|
| 188 | - $this->datec = $this->db->jdate($obj->datec); |
|
| 189 | - $this->tms = $obj->tms; |
|
| 190 | - $this->fk_user_author = $obj->fk_user_author; |
|
| 191 | - $this->fk_element = $obj->fk_element; |
|
| 192 | - $this->entity = $obj->entity; |
|
| 193 | - $this->import_key = $obj->import_key; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - $this->db->free($resql); |
|
| 197 | - |
|
| 198 | - if ($num_rows) return 1; |
|
| 199 | - else return 0; |
|
| 200 | - } |
|
| 201 | - else |
|
| 202 | - { |
|
| 203 | - $this->error="Error ".$this->db->lasterror(); |
|
| 204 | - return -1; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Update database |
|
| 211 | - * |
|
| 212 | - * @param User $user User that modify |
|
| 213 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 214 | - * @return int <=0 if KO, >0 if OK |
|
| 215 | - */ |
|
| 216 | - function update(User $user, $notrigger=0) |
|
| 217 | - { |
|
| 218 | - global $conf, $langs; |
|
| 219 | - $error=0; |
|
| 220 | - |
|
| 221 | - // Clean parameters |
|
| 222 | - if (isset($this->fk_element)) $this->fk_project=(int) trim($this->fk_element); |
|
| 223 | - if (isset($this->fk_user_author)) $this->fk_user_author=(int) trim($this->fk_user_author); |
|
| 224 | - if (isset($this->description)) $this->description=trim($this->description); |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - // Update request |
|
| 228 | - $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_comment SET"; |
|
| 229 | - $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").","; |
|
| 230 | - $sql.= " datec=".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null').","; |
|
| 231 | - $sql.= " fk_element=".(isset($this->fk_element)?$this->fk_element:"null").","; |
|
| 232 | - $sql.= " element_type='".$this->db->escape($this->element_type)."',"; |
|
| 233 | - $sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").","; |
|
| 234 | - $sql.= " entity=".(!empty($this->entity)?$this->entity:'1').","; |
|
| 235 | - $sql.= " import_key=".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); |
|
| 236 | - $sql.= " WHERE rowid=".$this->id; |
|
| 237 | - |
|
| 238 | - $this->db->begin(); |
|
| 239 | - |
|
| 240 | - dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
| 241 | - $resql = $this->db->query($sql); |
|
| 242 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 243 | - |
|
| 244 | - if (! $error) |
|
| 245 | - { |
|
| 246 | - if (! $notrigger) |
|
| 247 | - { |
|
| 248 | - // Call trigger |
|
| 249 | - $result=$this->call_trigger('TASK_COMMENT_MODIFY',$user); |
|
| 250 | - if ($result < 0) { $error++; } |
|
| 251 | - // End call triggers |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // Commit or rollback |
|
| 256 | - if ($error) |
|
| 257 | - { |
|
| 258 | - foreach($this->errors as $errmsg) |
|
| 259 | - { |
|
| 260 | - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
| 261 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 262 | - } |
|
| 263 | - $this->db->rollback(); |
|
| 264 | - return -1*$error; |
|
| 265 | - } |
|
| 266 | - else |
|
| 267 | - { |
|
| 268 | - $this->db->commit(); |
|
| 269 | - return 1; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Delete task from database |
|
| 276 | - * |
|
| 277 | - * @param User $user User that delete |
|
| 278 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 279 | - * @return int <0 if KO, >0 if OK |
|
| 280 | - */ |
|
| 281 | - function delete($user, $notrigger=0) |
|
| 282 | - { |
|
| 283 | - global $conf, $langs; |
|
| 284 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
|
| 285 | - |
|
| 286 | - $error=0; |
|
| 287 | - |
|
| 288 | - $this->db->begin(); |
|
| 289 | - |
|
| 290 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."comment"; |
|
| 291 | - $sql.= " WHERE rowid=".$this->id; |
|
| 292 | - |
|
| 293 | - $resql = $this->db->query($sql); |
|
| 294 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 295 | - |
|
| 296 | - if (! $error) |
|
| 297 | - { |
|
| 298 | - if (! $notrigger) |
|
| 299 | - { |
|
| 300 | - // Call trigger |
|
| 301 | - $result=$this->call_trigger('TASK_COMMENT_DELETE',$user); |
|
| 302 | - if ($result < 0) { $error++; } |
|
| 303 | - // End call triggers |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - // Commit or rollback |
|
| 308 | - if ($error) |
|
| 309 | - { |
|
| 310 | - foreach($this->errors as $errmsg) |
|
| 311 | - { |
|
| 312 | - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
| 313 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 314 | - } |
|
| 315 | - $this->db->rollback(); |
|
| 316 | - return -1*$error; |
|
| 317 | - }else{ |
|
| 318 | - $this->db->commit(); |
|
| 319 | - return 1; |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Load comments linked with current task |
|
| 326 | - * |
|
| 327 | - * @param string $element_type Element type |
|
| 328 | - * @param int $fk_element Id of element |
|
| 329 | - * @return array Comment array |
|
| 330 | - */ |
|
| 331 | - public function fetchAllFor($element_type, $fk_element) |
|
| 332 | - { |
|
| 333 | - global $db,$conf; |
|
| 334 | - $this->comments = array(); |
|
| 335 | - if(!empty($element_type) && !empty($fk_element)) { |
|
| 336 | - $sql = "SELECT"; |
|
| 337 | - $sql.= " c.rowid"; |
|
| 338 | - $sql.= " FROM ".MAIN_DB_PREFIX."comment as c"; |
|
| 339 | - $sql.= " WHERE c.fk_element = ".$fk_element; |
|
| 340 | - $sql.= " AND c.element_type = '".$db->escape($element_type)."'"; |
|
| 341 | - $sql.= " AND c.entity = ".$conf->entity; |
|
| 342 | - $sql.= " ORDER BY c.tms DESC"; |
|
| 343 | - |
|
| 344 | - dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG); |
|
| 345 | - $resql=$db->query($sql); |
|
| 346 | - if ($resql) |
|
| 347 | - { |
|
| 348 | - $num_rows = $db->num_rows($resql); |
|
| 349 | - if ($num_rows > 0) |
|
| 350 | - { |
|
| 351 | - while($obj = $db->fetch_object($resql)) |
|
| 352 | - { |
|
| 353 | - $comment = new self($db); |
|
| 354 | - $comment->fetch($obj->rowid); |
|
| 355 | - $this->comments[] = $comment; |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - $db->free($resql); |
|
| 359 | - } else { |
|
| 360 | - $this->errors[]="Error ".$this->db->lasterror(); |
|
| 361 | - return -1; |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - return count($this->comments); |
|
| 366 | - } |
|
| 53 | + public $fk_user_author; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var int Entity |
|
| 57 | + */ |
|
| 58 | + public $entity; |
|
| 59 | + |
|
| 60 | + public $import_key; |
|
| 61 | + |
|
| 62 | + public $comments = array(); |
|
| 63 | + |
|
| 64 | + public $oldcopy; |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Constructor |
|
| 69 | + * |
|
| 70 | + * @param DoliDB $db Database handler |
|
| 71 | + */ |
|
| 72 | + function __construct($db) |
|
| 73 | + { |
|
| 74 | + $this->db = $db; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Create into database |
|
| 80 | + * |
|
| 81 | + * @param User $user User that create |
|
| 82 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 83 | + * @return int <0 if KO, Id of created object if OK |
|
| 84 | + */ |
|
| 85 | + function create($user, $notrigger=0) |
|
| 86 | + { |
|
| 87 | + global $conf, $langs; |
|
| 88 | + |
|
| 89 | + $error=0; |
|
| 90 | + |
|
| 91 | + // Insert request |
|
| 92 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."comment ("; |
|
| 93 | + $sql.= "description"; |
|
| 94 | + $sql.= ", datec"; |
|
| 95 | + $sql.= ", fk_element"; |
|
| 96 | + $sql.= ", element_type"; |
|
| 97 | + $sql.= ", fk_user_author"; |
|
| 98 | + $sql.= ", entity"; |
|
| 99 | + $sql.= ", import_key"; |
|
| 100 | + $sql.= ") VALUES ("; |
|
| 101 | + $sql.= "'".$this->db->escape($this->description)."'"; |
|
| 102 | + $sql.= ", ".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null'); |
|
| 103 | + $sql.= ", '".(isset($this->fk_element)?$this->fk_element:"null")."'"; |
|
| 104 | + $sql.= ", '".$this->db->escape($this->element_type)."'"; |
|
| 105 | + $sql.= ", '".(isset($this->fk_user_author)?$this->fk_user_author:"null")."'"; |
|
| 106 | + $sql.= ", ".(!empty($this->entity)?$this->entity:'1'); |
|
| 107 | + $sql.= ", ".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); |
|
| 108 | + $sql.= ")"; |
|
| 109 | + |
|
| 110 | + //var_dump($this->db); |
|
| 111 | + //echo $sql; |
|
| 112 | + |
|
| 113 | + $this->db->begin(); |
|
| 114 | + |
|
| 115 | + dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 116 | + $resql=$this->db->query($sql); |
|
| 117 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 118 | + |
|
| 119 | + if (! $error) |
|
| 120 | + { |
|
| 121 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_comment"); |
|
| 122 | + |
|
| 123 | + if (! $notrigger) |
|
| 124 | + { |
|
| 125 | + // Call trigger |
|
| 126 | + $result=$this->call_trigger('TASK_COMMENT_CREATE',$user); |
|
| 127 | + if ($result < 0) { $error++; } |
|
| 128 | + // End call triggers |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Commit or rollback |
|
| 133 | + if ($error) |
|
| 134 | + { |
|
| 135 | + foreach($this->errors as $errmsg) |
|
| 136 | + { |
|
| 137 | + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
| 138 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 139 | + } |
|
| 140 | + $this->db->rollback(); |
|
| 141 | + return -1*$error; |
|
| 142 | + } |
|
| 143 | + else |
|
| 144 | + { |
|
| 145 | + $this->db->commit(); |
|
| 146 | + return $this->id; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Load object in memory from database |
|
| 153 | + * |
|
| 154 | + * @param int $id Id object |
|
| 155 | + * @param int $ref ref object |
|
| 156 | + * @return int <0 if KO, 0 if not found, >0 if OK |
|
| 157 | + */ |
|
| 158 | + function fetch($id, $ref='') |
|
| 159 | + { |
|
| 160 | + global $langs; |
|
| 161 | + |
|
| 162 | + $sql = "SELECT"; |
|
| 163 | + $sql.= " c.rowid,"; |
|
| 164 | + $sql.= " c.description,"; |
|
| 165 | + $sql.= " c.datec,"; |
|
| 166 | + $sql.= " c.tms,"; |
|
| 167 | + $sql.= " c.fk_element,"; |
|
| 168 | + $sql.= " c.element_type,"; |
|
| 169 | + $sql.= " c.fk_user_author,"; |
|
| 170 | + $sql.= " c.entity,"; |
|
| 171 | + $sql.= " c.import_key"; |
|
| 172 | + $sql.= " FROM ".MAIN_DB_PREFIX."comment as c"; |
|
| 173 | + $sql.= " WHERE c.rowid = ".$id; |
|
| 174 | + |
|
| 175 | + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
| 176 | + $resql=$this->db->query($sql); |
|
| 177 | + if ($resql) |
|
| 178 | + { |
|
| 179 | + $num_rows = $this->db->num_rows($resql); |
|
| 180 | + |
|
| 181 | + if ($num_rows) |
|
| 182 | + { |
|
| 183 | + $obj = $this->db->fetch_object($resql); |
|
| 184 | + |
|
| 185 | + $this->id = $obj->rowid; |
|
| 186 | + $this->description = $obj->description; |
|
| 187 | + $this->element_type = $obj->element_type; |
|
| 188 | + $this->datec = $this->db->jdate($obj->datec); |
|
| 189 | + $this->tms = $obj->tms; |
|
| 190 | + $this->fk_user_author = $obj->fk_user_author; |
|
| 191 | + $this->fk_element = $obj->fk_element; |
|
| 192 | + $this->entity = $obj->entity; |
|
| 193 | + $this->import_key = $obj->import_key; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + $this->db->free($resql); |
|
| 197 | + |
|
| 198 | + if ($num_rows) return 1; |
|
| 199 | + else return 0; |
|
| 200 | + } |
|
| 201 | + else |
|
| 202 | + { |
|
| 203 | + $this->error="Error ".$this->db->lasterror(); |
|
| 204 | + return -1; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Update database |
|
| 211 | + * |
|
| 212 | + * @param User $user User that modify |
|
| 213 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 214 | + * @return int <=0 if KO, >0 if OK |
|
| 215 | + */ |
|
| 216 | + function update(User $user, $notrigger=0) |
|
| 217 | + { |
|
| 218 | + global $conf, $langs; |
|
| 219 | + $error=0; |
|
| 220 | + |
|
| 221 | + // Clean parameters |
|
| 222 | + if (isset($this->fk_element)) $this->fk_project=(int) trim($this->fk_element); |
|
| 223 | + if (isset($this->fk_user_author)) $this->fk_user_author=(int) trim($this->fk_user_author); |
|
| 224 | + if (isset($this->description)) $this->description=trim($this->description); |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + // Update request |
|
| 228 | + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_comment SET"; |
|
| 229 | + $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").","; |
|
| 230 | + $sql.= " datec=".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null').","; |
|
| 231 | + $sql.= " fk_element=".(isset($this->fk_element)?$this->fk_element:"null").","; |
|
| 232 | + $sql.= " element_type='".$this->db->escape($this->element_type)."',"; |
|
| 233 | + $sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").","; |
|
| 234 | + $sql.= " entity=".(!empty($this->entity)?$this->entity:'1').","; |
|
| 235 | + $sql.= " import_key=".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null"); |
|
| 236 | + $sql.= " WHERE rowid=".$this->id; |
|
| 237 | + |
|
| 238 | + $this->db->begin(); |
|
| 239 | + |
|
| 240 | + dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
| 241 | + $resql = $this->db->query($sql); |
|
| 242 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 243 | + |
|
| 244 | + if (! $error) |
|
| 245 | + { |
|
| 246 | + if (! $notrigger) |
|
| 247 | + { |
|
| 248 | + // Call trigger |
|
| 249 | + $result=$this->call_trigger('TASK_COMMENT_MODIFY',$user); |
|
| 250 | + if ($result < 0) { $error++; } |
|
| 251 | + // End call triggers |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // Commit or rollback |
|
| 256 | + if ($error) |
|
| 257 | + { |
|
| 258 | + foreach($this->errors as $errmsg) |
|
| 259 | + { |
|
| 260 | + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
| 261 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 262 | + } |
|
| 263 | + $this->db->rollback(); |
|
| 264 | + return -1*$error; |
|
| 265 | + } |
|
| 266 | + else |
|
| 267 | + { |
|
| 268 | + $this->db->commit(); |
|
| 269 | + return 1; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Delete task from database |
|
| 276 | + * |
|
| 277 | + * @param User $user User that delete |
|
| 278 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 279 | + * @return int <0 if KO, >0 if OK |
|
| 280 | + */ |
|
| 281 | + function delete($user, $notrigger=0) |
|
| 282 | + { |
|
| 283 | + global $conf, $langs; |
|
| 284 | + require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
|
| 285 | + |
|
| 286 | + $error=0; |
|
| 287 | + |
|
| 288 | + $this->db->begin(); |
|
| 289 | + |
|
| 290 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."comment"; |
|
| 291 | + $sql.= " WHERE rowid=".$this->id; |
|
| 292 | + |
|
| 293 | + $resql = $this->db->query($sql); |
|
| 294 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 295 | + |
|
| 296 | + if (! $error) |
|
| 297 | + { |
|
| 298 | + if (! $notrigger) |
|
| 299 | + { |
|
| 300 | + // Call trigger |
|
| 301 | + $result=$this->call_trigger('TASK_COMMENT_DELETE',$user); |
|
| 302 | + if ($result < 0) { $error++; } |
|
| 303 | + // End call triggers |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + // Commit or rollback |
|
| 308 | + if ($error) |
|
| 309 | + { |
|
| 310 | + foreach($this->errors as $errmsg) |
|
| 311 | + { |
|
| 312 | + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
| 313 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 314 | + } |
|
| 315 | + $this->db->rollback(); |
|
| 316 | + return -1*$error; |
|
| 317 | + }else{ |
|
| 318 | + $this->db->commit(); |
|
| 319 | + return 1; |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Load comments linked with current task |
|
| 326 | + * |
|
| 327 | + * @param string $element_type Element type |
|
| 328 | + * @param int $fk_element Id of element |
|
| 329 | + * @return array Comment array |
|
| 330 | + */ |
|
| 331 | + public function fetchAllFor($element_type, $fk_element) |
|
| 332 | + { |
|
| 333 | + global $db,$conf; |
|
| 334 | + $this->comments = array(); |
|
| 335 | + if(!empty($element_type) && !empty($fk_element)) { |
|
| 336 | + $sql = "SELECT"; |
|
| 337 | + $sql.= " c.rowid"; |
|
| 338 | + $sql.= " FROM ".MAIN_DB_PREFIX."comment as c"; |
|
| 339 | + $sql.= " WHERE c.fk_element = ".$fk_element; |
|
| 340 | + $sql.= " AND c.element_type = '".$db->escape($element_type)."'"; |
|
| 341 | + $sql.= " AND c.entity = ".$conf->entity; |
|
| 342 | + $sql.= " ORDER BY c.tms DESC"; |
|
| 343 | + |
|
| 344 | + dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG); |
|
| 345 | + $resql=$db->query($sql); |
|
| 346 | + if ($resql) |
|
| 347 | + { |
|
| 348 | + $num_rows = $db->num_rows($resql); |
|
| 349 | + if ($num_rows > 0) |
|
| 350 | + { |
|
| 351 | + while($obj = $db->fetch_object($resql)) |
|
| 352 | + { |
|
| 353 | + $comment = new self($db); |
|
| 354 | + $comment->fetch($obj->rowid); |
|
| 355 | + $this->comments[] = $comment; |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + $db->free($resql); |
|
| 359 | + } else { |
|
| 360 | + $this->errors[]="Error ".$this->db->lasterror(); |
|
| 361 | + return -1; |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + return count($this->comments); |
|
| 366 | + } |
|
| 367 | 367 | } |