* Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * * 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 2 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'); // Security check $facid=GETPOST('facid','int'); $action=GETPOST("action"); if ($user->societe_id) $socid=$user->societe_id; $objecttype = 'facture_rec'; if ($action == "create" || $action == "add") $objecttype = ''; $result = restrictedArea($user, 'facture', $facid, $objecttype); if ($page == -1) { $page = 0 ; } $limit = $conf->liste_limit; $offset = $limit * $page ; if ($sortorder == "") $sortorder="DESC"; if ($sortfield == "") $sortfield="f.datef"; /* * Actions */ // Create predefined invoice if ($action == 'add') { $facturerec = new FactureRec($db); $facturerec->titre = $_POST["titre"]; $facturerec->note = $_POST["comment"]; if ($facturerec->create($user,$facid) > 0) { $facid = $facturerec->id; $action = ''; } else { $action = "create"; $mesg = '
'.$facturerec->error.'
'; } } // Suppression if ($action == 'delete' && $user->rights->facture->supprimer) { $facrec = new FactureRec($db); $facrec->fetch($facid); $facrec->delete(); $facid = 0 ; } /* * View */ llxHeader('',$langs->trans("RepeatableInvoices"),'ch-facture.html#s-fac-facture-rec'); $form = new Form($db); /* * Create mode */ if ($action == 'create') { print_fiche_titre($langs->trans("CreateRepeatableInvoice")); if ($mesg) print $mesg.'
'; $facture = new Facture($db); // Source invoice $product_static=new Product($db); if ($facture->fetch($facid) > 0) { print '
'; print ''; print ''; print ''; print ''; $facture->fetch_thirdparty(); print ''; print ''; print ''; print ''; print ""; print ""; print ""; if ($conf->projet->enabled) { print ""; } print "
'.$langs->trans("Customer").''.$facture->client->getNomUrl(1).''; //print $langs->trans("NotePrivate"); print '
'.$langs->trans("Title").''; print ''; print ''; print ''; print '
".$langs->trans("Author")."".$user->getFullName($langs)."
".$langs->trans("PaymentConditions").""; $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$facture->id,$facture->cond_reglement_id,'none'); print "
".$langs->trans("PaymentMode").""; $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$facture->id,$facture->mode_reglement_id,'none'); print "
".$langs->trans("Project").""; if ($facture->fk_project > 0) { $project = new Project($db); $project->fetch($facture->fk_project); print $project->title; } print "
"; print '
'; if ($conf->service->enabled) { print_titre($langs->trans("ProductsAndServices")); } else { print_titre($langs->trans("Products")); } /* * Invoice lines */ print ''; print ''; if ($flag_different_price) { print ''; } print ''; print "\n"; print "
'; $sql = 'SELECT l.fk_product, l.product_type, 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, l.total_ttc,'; $sql.= ' l.date_start,'; $sql.= ' l.date_end,'; $sql.= ' l.product_type,'; $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 = ".$facture->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 ''; print ''; print ''; 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=$objp->product_type?$objp->product_type:$objp->fk_product_type; if ($objp->fk_product) { print ''; } else { print '\n"; } print ''; print ''; if ($objp->remise_percent > 0) { print '\n"; } else { print ''; } print '\n"; if ($objp->fk_product > 0 && $objp->subprice <> $product->price) { print '\n"; $flag_different_price++; } else { print ''; } print ""; $i++; } $db->free($result); } else { print $db->error(); } print "
'.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("Qty").''.$langs->trans("ReductionShort").''.$langs->trans("PriceU").'N.P.
'; print ''; // ancre pour retourner sur la ligne // Show product and description $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; $product_static->ref=$objp->ref; $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); $text.= ' - '.$objp->product_label; $description=($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 ($conf->global->PRODUIT_DESC_IN_FORM) print ($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'); print $text.' '.nl2br($objp->description); // Show range print_date_range($db->jdate($objp->date_start),$db->jdate($objp->date_end)); print "'.$objp->tva_tx.' %'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice)."'.price($product->price)." 
"; print '
'; print ''; print '

\n"; } else { print "Erreur facture $facture->id inexistante"; } } else { /* * View mode */ if ($facid > 0) { $fac = new FactureRec($db); if ($fac->fetch($facid, $user->societe_id) > 0) { $soc = new Societe($db); $soc->fetch($fac->socid); $author = new User($db); $author->fetch($fac->user_author); dol_fiche_head($head, 'compta', $langs->trans("PredefinedInvoices"),0,'company'); // Add a div print ''; print ''; print ''; print ''; print ''; print ""; print ""; if ($fac->remise_percent > 0) { print '"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($fac->note) { print '"; } print "
'.$langs->trans("Ref").''.$fac->titre.'
'.$langs->trans("Customer").''.$soc->getNomUrl(1).'". $langs->trans("PaymentConditions") ." : "; $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'none'); print "
".$langs->trans("Author")."".$author->getFullName($langs)."'; } else { print ''; } print $langs->trans("PaymentMode") ." : "; $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'none'); print "
'.$langs->trans("AmountHT").''.price($fac->total_ht).''.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("AmountVAT").''.price($fac->total_tva).''.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("AmountTTC").''.price($fac->total_ttc).''.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("Note").' : '.nl2br($fac->note)."
"; print ''; /* * Lines */ if ($conf->service->enabled) { print_titre($langs->trans("ProductsAndServices")); } else { print_titre($langs->trans("Products")); } print ''; print ''; print ''; print ''; print ''; print ''; $num = count($fac->lines); $i = 0; $var=True; while ($i < $num) { $var=!$var; $product_static=new Product($db); // Show product and description $type=$fac->lines[$i]->product_type?$fac->lines[$i]->product_type:$fac->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 ($fac->lines[$i]->fk_product > 0) { print ''; } else { print ''; } print ""; print ''; print "\n"; $i++; } print '
'.$langs->trans("Description").''.$langs->trans("Price").''.$langs->trans("ReductionShort").''.$langs->trans("Qty").'
'; print ''; // ancre pour retourner sur la ligne // Show product and description $product_static->type=$fac->lines[$i]->fk_product_type; $product_static->id=$fac->lines[$i]->fk_product; $product_static->ref=$fac->lines[$i]->product_ref; $product_static->libelle=$fac->lines[$i]->libelle; $text=$product_static->getNomUrl(1); $text.= ' - '.$fac->lines[$i]->libelle; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($fac->lines[$i]->desc)); print $form->textwithtooltip($text,$description,3,'','',$i); // Show range print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end); // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) print ($fac->lines[$i]->desc && $fac->lines[$i]->desc!=$fac->lines[$i]->libelle)?'
'.dol_htmlentitiesbr($fac->lines[$i]->desc):''; print '
'; if ($type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); print $text.' '.nl2br($fac->lines[$i]->desc); // Show range print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end); print '".price($fac->lines[$i]->price)."'.$fac->lines[$i]->remise_percent.' %".$fac->lines[$i]->qty."
'; /** * Barre d'actions */ print '
'; if ($fac->statut == 0 && $user->rights->facture->supprimer) { print ''.$langs->trans('Delete').''; } print '
'; } else { print $langs->trans("ErrorRecordNotFound"); } } else { /* * List mode */ if ($user->rights->facture->lire) { $sql = "SELECT s.nom, s.rowid as socid, f.titre, f.total, f.rowid as facid"; $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); $result = $db->query($sql); } if ($result) { $num = $db->num_rows($result); print_barre_liste($langs->trans("RepeatableInvoices"),$page,$_SERVER['PHP_SELF'],"&socid=$socid",$sortfield,$sortorder,'',$num); $i = 0; print ''; print ''; print ''; print_liste_field_titre($langs->trans("Company"),$_SERVER['PHP_SELF'],"s.nom","","&socid=$socid","",$sortfiled,$sortorder); print ''; print ''; print "\n"; if ($num > 0) { $var=True; while ($i < min($num,$limit)) { $objp = $db->fetch_object($result); $var=!$var; print ""; print '\n"; print ''; print ''."\n"; if (! $objp->paye) { if ($objp->fk_statut == 0) { print ''; } else { print ''; } } else { print ''; } print "\n"; $i++; } } print "
'.$langs->trans("Ref").''.$langs->trans("Amount").' 
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre; print "'.$objp->nom.''.price($objp->total).''.$langs->trans("Draft").''.$langs->trans("Validated").' 
"; $db->free(); } else { dol_print_error($db); } } } llxFooter(); $db->close(); ?>