* Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2013 Florian Henry * Copyright (C) 2013 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2015 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/compta/facture/fiche-rec.php * \ingroup facture * \brief Page to show predefined invoice */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $langs->load('bills'); $langs->load('compta'); // Security check $id=(GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int')); $action=GETPOST('action', 'alpha'); if ($user->societe_id) $socid=$user->societe_id; $objecttype = 'facture_rec'; if ($action == "create" || $action == "add") $objecttype = ''; $result = restrictedArea($user, 'facture', $id, $objecttype); if ($page == -1) { $page = 0 ; } $limit = $conf->liste_limit; $offset = $limit * $page ; if ($sortorder == "") $sortorder="DESC"; if ($sortfield == "") $sortfield="f.datef"; $object = new FactureRec($db); /* * Actions */ // Create predefined invoice if ($action == 'add') { if (! GETPOST('titre')) { setEventMessage($langs->transnoentities("ErrorFieldRequired",$langs->trans("Title")), 'errors'); $action = "create"; $error++; } if (! $error) { $object->titre = GETPOST('titre', 'alpha'); $object->note_private = GETPOST('note_private'); $object->usenewprice = GETPOST('usenewprice'); if ($object->create($user, $id) > 0) { $id = $object->id; $action = ''; } else { setEventMessage($object->error, 'errors'); $action = "create"; } } } // Suppression if ($action == 'delete' && $user->rights->facture->supprimer) { $object->fetch($id); $object->delete(); $id = 0 ; } /* * View */ llxHeader('',$langs->trans("RepeatableInvoices"),'ch-facture.html#s-fac-facture-rec'); $form = new Form($db); $companystatic = new Societe($db); /* * Create mode */ if ($action == 'create') { print_fiche_titre($langs->trans("CreateRepeatableInvoice"),'','title_accountancy.png'); $object = new Facture($db); // Source invoice $product_static = new Product($db); if ($object->fetch($id) > 0) { print '
'; print ''; print ''; print ''; dol_fiche_head(); $rowspan=4; if (! empty($conf->projet->enabled) && $object->fk_project > 0) $rowspan++; print ''; $object->fetch_thirdparty(); // Third party print ''; print ''; // Title print ''; // Note print ''; // Author print ""; // Payment term print ""; // Payment mode print ""; // Project if (! empty($conf->projet->enabled) && $object->fk_project > 0) { print ""; } print "
'.$langs->trans("Customer").''.$object->client->getNomUrl(1,'customer').''; print $langs->trans("Comment"); print '
'.$langs->trans("Title").''; print ''; print ''; print ''; print '
".$langs->trans("Author")."".$user->getFullName($langs)."
".$langs->trans("PaymentConditions").""; $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none'); print "
".$langs->trans("PaymentMode").""; $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none'); print "
".$langs->trans("Project").""; if ($object->fk_project > 0) { $project = new Project($db); $project->fetch($object->fk_project); print $project->title; } print "
"; print '
'; $title = $langs->trans("ProductsAndServices"); if (empty($conf->service->enabled)) $title = $langs->trans("Products"); else if (empty($conf->product->enabled)) $title = $langs->trans("Services"); print_titre($title); /* * Invoice lines */ print ''; print ''; if ($flag_price_may_change) { print ''; } print "
'; $sql = 'SELECT l.fk_product, l.product_type, l.label as custom_label, l.description, l.qty, l.rowid, l.tva_tx,'; $sql.= ' l.fk_remise_except,'; $sql.= ' l.remise_percent, l.subprice, l.info_bits,'; $sql.= ' l.total_ht, l.total_tva as total_vat, l.total_ttc,'; $sql.= ' l.date_start,'; $sql.= ' l.date_end,'; $sql.= ' l.product_type,'; $sql.= ' l.fk_unit,'; $sql.= ' p.ref, p.fk_product_type, p.label as product_label,'; $sql.= ' p.description as product_desc'; $sql.= " FROM ".MAIN_DB_PREFIX."facturedet as l"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid"; $sql.= " WHERE l.fk_facture = ".$object->id; $sql.= " ORDER BY l.rowid"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; $total = 0; echo ''; if ($num) { print ''; print ''; print ''; print ''; if ($conf->global->PRODUCT_USE_UNITS) { print ''; } print ''; print ''; print ''; print ''; print ''; if (empty($conf->global->PRODUIT_MULTIPRICES)) print ''; print "\n"; } $var=true; while ($i < $num) { $objp = $db->fetch_object($result); if ($objp->fk_product > 0) { $product = New Product($db); $product->fetch($objp->fk_product); } $var=!$var; print ""; // Show product and description $type=(isset($objp->product_type)?$objp->product_type:$objp->fk_product_type); $product_static->fk_unit=$objp->fk_unit; if ($objp->fk_product > 0) { print ''; } else { print '\n"; } // Vat rate print ''; // Qty print ''; if ($conf->global->PRODUCT_USE_UNITS) { print ''; } // Percent if ($objp->remise_percent > 0) { print '\n"; } else { print ''; } // Total HT print '\n"; // Total VAT print '\n"; // Total TTC print '\n"; // Total Unit price print '\n"; // Current price of product if (empty($conf->global->PRODUIT_MULTIPRICES)) { if ($objp->fk_product > 0) { $flag_price_may_change++; $prodprice=$product_static->price; // price HT print '\n"; } else { print ''; } } print ""; $i++; } $db->free($result); } else { print $db->error(); } print "
'.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("Qty").''.$langs->trans("Unit").''.$langs->trans("ReductionShort").''.$langs->trans("TotalHT").''.$langs->trans("TotalVAT").''.$langs->trans("TotalTTC").''.$langs->trans("PriceUHT").''.$langs->trans("CurrentProductPrice").'
'; print ''; // ancre pour retourner sur la ligne // Show product and description $product_static->fetch($objp->fk_product); // We need all information later $text=$product_static->getNomUrl(1); $text.= ' - '.(! empty($objp->custom_label)?$objp->custom_label:$objp->product_label); $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($objp->description)); print $form->textwithtooltip($text,$description,3,'','',$i); // Show range print_date_range($db->jdate($objp->date_start), $db->jdate($objp->date_end)); // Add description in form if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) print (! empty($objp->description) && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; print '
'; print ''; // ancre pour retourner sur la ligne if ($type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); if (! empty($objp->custom_label)) { $text.= ' '.$objp->custom_label.''; print $form->textwithtooltip($text,dol_htmlentitiesbr($objp->description),3,'','',$i); } else { print $text.' '.nl2br($objp->description); } // Show range print_date_range($db->jdate($objp->date_start), $db->jdate($objp->date_end)); print "'.vatrate($objp->tva_tx).'%'.$objp->qty.''.$product_static->getLabelOfUnit().''.$objp->remise_percent." % '.price($objp->total_ht)."'.price($objp->total_vat)."'.price($objp->total_ttc)."'.price($objp->subprice)."'.price($prodprice)." 
"; print '
'; print ''; print '
\n"; dol_fiche_end(); print '
'; print '     '; print ''; print '
'; print "
\n"; } else { dol_print_error('',"Error, no invoice ".$object->id); } } else { /* * View mode */ if ($id > 0) { if ($object->fetch($id) > 0) { $object->fetch_thirdparty(); $author = new User($db); $author->fetch($object->user_author); $head=array(); $h=0; $head[$h][0] = $_SERVER["PHP_SELF"].'?id='.$object->id; $head[$h][1] = $langs->trans("CardBill"); $head[$h][2] = 'card'; dol_fiche_head($head, 'card', $langs->trans("PredefinedInvoices"),0,'bill'); // Add a div print ''; print ''; print ''; print ''; print ''; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Payment term print '"; // Payment mode print '"; print '"; print "
'.$langs->trans("Ref").''.$object->titre.'
'.$langs->trans("Customer").''.$object->thirdparty->getNomUrl(1,'customer').'
".$langs->trans("Author").''.$author->getFullName($langs)."
'.$langs->trans("AmountHT").''.price($object->total_ht,'',$langs,1,-1,-1,$conf->currency).'
'.$langs->trans("AmountVAT").''.price($object->total_tva,'',$langs,1,-1,-1,$conf->currency).'
'.$langs->trans("AmountTTC").''.price($object->total_ttc,'',$langs,1,-1,-1,$conf->currency).'
'.$langs->trans("PaymentConditions").''; $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id,'none'); print "
'.$langs->trans("PaymentMode").''; $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id,'none'); print "
'.$langs->trans("Comment").''.nl2br($object->note_private)."
"; print ''; /* * Lines */ $title = $langs->trans("ProductsAndServices"); if (empty($conf->service->enabled)) $title = $langs->trans("Products"); else if (empty($conf->product->enabled)) $title = $langs->trans("Services"); print_titre($title); print ''; print ''; print ''; print ''; print ''; print ''; if ($conf->global->PRODUCT_USE_UNITS) { print ''; } print ''; $num = count($object->lines); $i = 0; $var=true; while ($i < $num) { $var=!$var; $product_static=new Product($db); // Show product and description $type=(isset($object->lines[$i]->product_type)?$object->lines[$i]->product_type:$object->lines[$i]->fk_product_type); // Try to enhance type detection using date_start and date_end for free lines when type // was not saved. if (! empty($objp->date_start)) $type=1; if (! empty($objp->date_end)) $type=1; // Show line print ""; if ($object->lines[$i]->fk_product > 0) { print ''; } else { print ''; } print ''; print ''; print ''; if ($conf->global->PRODUCT_USE_UNITS) { print ""; } print "\n"; $i++; } print '
'.$langs->trans("Description").''.$langs->trans("Price").''.$langs->trans("ReductionShort").''.$langs->trans("Qty").''.$langs->trans("Unit").'
'; print ''; // ancre pour retourner sur la ligne // Show product and description $product_static->type=$object->lines[$i]->fk_product_type; $product_static->id=$object->lines[$i]->fk_product; $product_static->ref=$object->lines[$i]->product_ref; $text=$product_static->getNomUrl(1); $text.= ' - '.(! empty($object->lines[$i]->label)?$object->lines[$i]->label:$object->lines[$i]->product_label); $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($object->lines[$i]->desc)); print $form->textwithtooltip($text,$description,3,'','',$i); // Show range print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end); // Add description in form if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) print (! empty($object->lines[$i]->desc) && $object->lines[$i]->desc!=$fac->lines[$i]->product_label)?'
'.dol_htmlentitiesbr($object->lines[$i]->desc):''; print '
'; if ($type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); if (! empty($object->lines[$i]->label)) { $text.= ' '.$object->lines[$i]->label.''; print $form->textwithtooltip($text,dol_htmlentitiesbr($object->lines[$i]->desc),3,'','',$i); } else { print $text.' '.nl2br($object->lines[$i]->desc); } // Show range print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end); print ''.price($object->lines[$i]->price).''.$object->lines[$i]->remise_percent.' %'.$object->lines[$i]->qty.'".$object->lines[$i]->getLabelOfUnit()."
'; /** * Barre d'actions */ print '
'; if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->creer) { echo ''; } if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->supprimer) { print ''; } print '
'; } else { print $langs->trans("ErrorRecordNotFound"); } } else { /* * List mode */ $sql = "SELECT s.nom as name, s.rowid as socid, f.rowid as facid, f.titre, f.total, f.tva as total_vat, f.total_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f"; $sql.= " WHERE f.fk_soc = s.rowid"; $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql .= " AND s.rowid = ".$socid; //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC "; // $sql .= $db->plimit($limit + 1,$offset); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); print_barre_liste($langs->trans("RepeatableInvoices"),$page,$_SERVER['PHP_SELF'],"&socid=$socid",$sortfield,$sortorder,'',$num,'','title_accountancy.png'); print $langs->trans("ToCreateAPredefinedInvoice").'

'; $i = 0; print ''; print ''; print_liste_field_titre($langs->trans("Ref")); print_liste_field_titre($langs->trans("Company"),$_SERVER['PHP_SELF'],"s.nom","","&socid=$socid","",$sortfiled,$sortorder); print_liste_field_titre($langs->trans("AmountHT"),'','','','','align="right"'); print_liste_field_titre($langs->trans("AmountVAT"),'','','','','align="right"'); print_liste_field_titre($langs->trans("AmountTTC"),'','','','','align="right"'); print_liste_field_titre(''); // Field may contains ling text print "\n"; if ($num > 0) { $var=true; while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); $var=!$var; print ""; print '\n"; $companystatic->id=$objp->socid; $companystatic->name=$objp->name; print ''; print ''."\n"; print ''."\n"; print ''."\n"; print '"; print "\n"; $i++; } } else print ''; print "
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre; print "'.$companystatic->getNomUrl(1,'customer').''.price($objp->total).''.price($objp->total_vat).''.price($objp->total_ttc).''; if ($user->rights->facture->creer) { print ''; print $langs->trans("CreateBill").''; } else { print " "; } print "
'.$langs->trans("NoneF").'
"; $db->free($resql); } else { dol_print_error($db); } } } llxFooter(); $db->close();