* * 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ * */ require("./pre.inc.php"); $user->getrights('commande'); if (!$user->rights->commande->lire) accessforbidden(); require("../commande.class.php"); require("../project.class.php"); require("../propal.class.php"); llxHeader(); /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * */ if ($HTTP_POST_VARS["action"] == 'classin') { $commande = new Commande($db); $commande->fetch($facid); $commande->classin($HTTP_POST_VARS["projetid"]); } /* * */ if ($HTTP_POST_VARS["action"] == 'add') { $datecommande = mktime(12, 0 , 0, $remonth, $reday, $reyear); $commande = new Commande($db, $socid); $commande->number = $HTTP_POST_VARS["facnumber"]; $commande->date = $datecommande; $commande->note = $HTTP_POST_VARS["note"]; if ($HTTP_POST_VARS["fac_rec"] > 0) { /* * Commande récurrente */ $commande->fac_rec = $HTTP_POST_VARS["fac_rec"]; $facid = $commande->create($user); } else { $commande->projetid = $HTTP_POST_VARS["projetid"]; $commande->cond_reglement = $HTTP_POST_VARS["condid"]; $commande->amount = $HTTP_POST_VARS["amount"]; $commande->remise = $HTTP_POST_VARS["remise"]; $commande->remise_percent = $HTTP_POST_VARS["remise_percent"]; if (!$HTTP_POST_VARS["propalid"]) { $commande->add_product($HTTP_POST_VARS["idprod1"],$HTTP_POST_VARS["qty1"],$HTTP_POST_VARS["remise_percent1"]); $commande->add_product($HTTP_POST_VARS["idprod2"],$HTTP_POST_VARS["qty2"],$HTTP_POST_VARS["remise_percent2"]); $commande->add_product($HTTP_POST_VARS["idprod3"],$HTTP_POST_VARS["qty3"],$HTTP_POST_VARS["remise_percent3"]); $commande->add_product($HTTP_POST_VARS["idprod4"],$HTTP_POST_VARS["qty4"],$HTTP_POST_VARS["remise_percent4"]); $facid = $commande->create($user); } else { $commande->propalid = $HTTP_POST_VARS["propalid"]; $facid = $commande->create($user); if ($facid) { $prop = New Propal($db); if ( $prop->fetch($HTTP_POST_VARS["propalid"]) ) { for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) { $result = $commande->addline($facid, addslashes($prop->lignes[$i]->libelle), $prop->lignes[$i]->subprice, $prop->lignes[$i]->qty, $prop->lignes[$i]->tva_tx, $prop->lignes[$i]->product_id, $prop->lignes[$i]->remise_percent); } } else { print "Erreur"; } } else { print "

Erreur : la commande n'a pas été créée, vérifier le numéro !"; print "

Retour à la propal"; print $db->error(); } } } $action = ''; } /* * */ if ($HTTP_POST_VARS["action"] == 'confirm_valid' && $HTTP_POST_VARS["confirm"] == yes && $user->rights->commande->valider) { $fac = new Commande($db); $fac->fetch($facid); $soc = new Societe($db); $soc->fetch($fac->socidp); $result = $fac->set_valid($facid, $user, $soc); if ($result) { commande_pdf_create($db, $facid); } } if ($action == 'payed' && $user->rights->commande->paiement) { $fac = new Commande($db); $result = $fac->set_payed($facid); } if ($HTTP_POST_VARS["action"] == 'setremise' && $user->rights->commande->creer) { $fac = new Commande($db); $fac->fetch($facid); $fac->set_remise($user, $HTTP_POST_VARS["remise"]); } if ($action == 'addligne' && $user->rights->commande->creer) { $fac = new Commande($db); $fac->fetch($facid); $result = $fac->addline($facid, $HTTP_POST_VARS["desc"], $HTTP_POST_VARS["pu"], $HTTP_POST_VARS["qty"], $HTTP_POST_VARS["tva_tx"], 0, $HTTP_POST_VARS["remise_percent"]); } if ($action == 'updateligne' && $user->rights->commande->creer) { $fac = new Commande($db,"",$facid); $fac->fetch($facid); $result = $fac->updateline($rowid, $HTTP_POST_VARS["desc"], $HTTP_POST_VARS["price"], $HTTP_POST_VARS["qty"], $HTTP_POST_VARS["remise_percent"]); } if ($action == 'deleteline' && $user->rights->commande->creer) { $fac = new Commande($db,"",$facid); $fac->fetch($facid); $result = $fac->deleteline($rowid); } if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] == yes) { if ($user->rights->commande->supprimer ) { $fac = new Commande($db); $fac->delete($facid); $facid = 0 ; } } /* * */ if ($action == 'send') { $fac = new Commande($db,"",$facid); $fac->fetch($facid); $soc = new Societe($db, $fac->socidp); $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".pdf"; if (file_exists($file)) { $sendto = $soc->contact_get_email($HTTP_POST_VARS["destinataire"]); $sendtoid = $HTTP_POST_VARS["destinataire"]; if (strlen($sendto)) { $subject = "Commande $fac->ref"; $message = "Veuillez trouver ci-joint la commande $fac->ref\n\nCordialement\n\n"; $filename = "$fac->ref.pdf"; $replyto = $HTTP_POST_VARS["replytoname"] . " <".$HTTP_POST_VARS["replytomail"] .">"; $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$file, "application/pdf", $filename); if ( $mailfile->sendfile() ) { $sendto = htmlentities($sendto); $sql = "INSERT INTO llx_actioncomm (datea,fk_action,fk_soc,note,fk_commande, fk_contact,fk_user_author, label, percent) VALUES (now(), 9 ,$fac->socidp ,'Envoyée à $sendto',$fac->id, $sendtoid, $user->id, 'Envoi Commande par mail',100);"; if (! $db->query($sql) ) { print $db->error(); print "

$sql

"; } } else { print "!! erreur d'envoi
$sendto
$replyto
$filename"; } } else { print "Can't get email $sendto"; } } } /* * */ if ($HTTP_POST_VARS["action"] == 'relance') { $fac = new Commande($db,"",$facid); $fac->fetch($facid); $fac->send_relance($HTTP_POST_VARS["destinataire"], $HTTP_POST_VARS["replytoname"], $HTTP_POST_VARS["replytomail"], $user); } /* * */ if ($action == 'pdf') { /* * Generation de la commande * définit dans /includes/modules/commande/modules_commande.php */ commande_pdf_create($db, $facid); } $html = new Form($db); /********************************************************************* * * Mode creation * * * ************************************************************************/ if ($action == 'create') { print_titre("Emettre une commande"); if ($propalid) { $sql = "SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, ".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst"; $sql .= " FROM llx_societe as s, llx_propal as p, c_propalst as c"; $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id"; $sql .= " AND p.rowid = $propalid"; } else { $sql = "SELECT s.nom, s.prefix_comm, s.idp "; $sql .= "FROM llx_societe as s "; $sql .= "WHERE s.idp = $socidp"; } if ( $db->query($sql) ) { $num = $db->num_rows(); if ($num) { $obj = $db->fetch_object(0); $soc = new Societe($db); $soc->fetch($obj->idp); print '
'; print ''; print '' ."\n"; print ''; print ''; print ''; print ''; print ""; print ''; print ""; print ""; print ''; print ""; print ""; if ($propalid > 0) { $amount = ($obj->price); print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''; print ''; print ''; print '"; print '"; } else { print ''; print ''; } /* * Commandes récurrentes * */ if ($propalid == 0) { $sql = "SELECT r.rowid, r.titre, r.amount FROM llx_commande_rec as r"; $sql .= " WHERE r.fk_soc = $socidp"; if ( $db->query($sql) ) { $num = $db->num_rows(); $i = 0; if ($num > 0) { print ''; } $db->free(); } else { print "$sql"; } } /* * */ print ''; print "\n"; print "
Client :'.$obj->nom.'Commentaire
Auteur :".$user->fullname."'; print '
Date :"; print_date_select(time()); print "
Numéro :Provisoire
Conditions de réglement :"; $sql = "SELECT rowid, libelle FROM llx_cond_reglement ORDER BY sortorder"; $result = $db->query($sql); $conds=array(); if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($i); $conds[$objp->rowid]=$objp->libelle; $i++; } $db->free(); } $html->select_array("condid",$conds); print "
Projet :"; $proj = new Project($db); $html->select_array("projetid",$proj->liste_array($socidp)); print "
Proposition'.$obj->ref.'
Montant HT'.price($amount).'
TVA'.price($obj->tva)."
Total TTC'.price($obj->total)."
Services/Produits
'; /* * * Liste des elements * */ $sql = "SELECT p.rowid,p.label,p.ref,p.price FROM llx_product as p "; $sql .= " WHERE envente = 1"; $sql .= " ORDER BY p.nbvente DESC LIMIT 20"; if ( $db->query($sql) ) { $opt = ""; if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object( $i); $opt .= "\n"; $i++; } } $db->free(); } else { print $db->error(); } print ''; print ''; for ($i = 1 ; $i < 5 ; $i++) { print ''; print ''; print ''; } print '
ProduitQuan.Remise
%
'; print '
Commandes récurrentes :
\n"; if ($propalid) { /* * Produits */ print_titre("Produits"); print ''; print ''; print ''; $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent"; $sql .= " FROM llx_propaldet as pt, llx_product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propalid"; $sql .= " ORDER BY pt.rowid ASC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $var=True; while ($i < $num) { $objp = $db->fetch_object($i); $var=!$var; print "\n"; print ''; print ""; print ''; print "\n"; $i++; } } $sql = "SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent"; $sql .= " FROM llx_propaldet as pt WHERE pt.fk_propal = $propalid AND pt.fk_product = 0"; $sql .= " ORDER BY pt.rowid ASC"; if ($db->query($sql)) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($i); $var=!$var; print "\n"; print ''; print ''; print ''; print "\n"; $i++; } } else { print $sql; } print '
RéfProduitPrixRemiseQté.
[$objp->ref]'.$objp->product.'".price($objp->price)."'.$objp->remise_percent.' %".$objp->qty."
 '.$objp->product.''.price($objp->price).''.$objp->remise_percent.' %".$objp->qty."
'; } } } else { print $db->error(); } } else /* *************************************************************************** */ /* */ /* */ /* */ /* *************************************************************************** */ { if ($facid > 0) { $fac = New Commande($db); if ( $fac->fetch($facid, $user->societe_id) > 0) { $soc = new Societe($db, $fac->socidp); $soc->fetch($fac->socidp); $author = new User($db); $author->id = $fac->user_author; $author->fetch(); print_titre("Commande : ".$fac->ref); /* * Confirmation de la suppression de la commande * */ if ($action == 'delete') { $html->form_confirm("$PHP_SELF?facid=$facid","Supprimer la commande","Etes-vous sûr de vouloir supprimer cette commande ?","confirm_delete"); } /* * Confirmation de la validation * */ if ($action == 'valid') { $numfa = commande_get_num($soc); $html->form_confirm("$PHP_SELF?facid=$facid","Valider la commande","Etes-vous sûr de vouloir valider cette commande avec le numéro $numfa ?","confirm_valid"); } /* * Commande */ print ''; print ""; print "'; print ""; print ""; print "\n"; print ""; print '"; print ""; if ($fac->remise_percent > 0) { print '"; print ''; print ''; print ''; if ($fac->remise_percent > 0) { print ''; print ''; print ''; } print ''; print ''; print ''; print ''; if ($fac->note) { print '"; } print "
Client"; print ''.$soc->nom.'Conditions de réglement : " . $fac->cond_reglement ."
Date".strftime("%A %d %B %Y",$fac->date)."Date limite de réglement : " . strftime("%d %B %Y",$fac->date_lim_reglement) ."
Projet'; if ($fac->projetid > 0) { $projet = New Project($db); $projet->fetch($fac->projetid); print ''.$projet->title.''; } else { print 'Classer la commande'; } print " Paiements
Auteur$author->fullname'; } else { print ''; } /* * Paiements */ $sql = "SELECT ".$db->pdate("datep")." as dp, p.amount, c.libelle as paiement_type, p.num_paiement, p.rowid"; $sql .= " FROM llx_paiement as p, c_paiement as c WHERE p.fk_commande = $facid AND p.fk_paiement = c.id"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $total = 0; echo ''; print ''; print ""; if (! $fac->paye) { print ""; } print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object( $i); $var=!$var; print ""; print "\n"; print "\n"; print '\n"; if (! $fac->paye && $user->rights->commande->paiement) { print '"; $total = $total + $objp->amount; $i++; } if ($fac->paye == 0) { print "\n"; print "\n"; $resteapayer = price($fac->total_ttc - $total); print ""; print "\n"; } print "
DateTypeMontant  
".strftime("%d %B %Y",$objp->dp)."$objp->paiement_type $objp->num_paiement'.price($objp->amount)."$_MONNAIEDel'; } print "
Total :".price($total)."$_MONNAIE
Facturé :".price($fac->total_ttc)."$_MONNAIE
Reste à payer :".price($fac->total_ttc - $total)."$_MONNAIE
"; $db->free(); } else { print $db->error(); } print "
Montant'.price($fac->total_ht).''.MAIN_MONNAIE.' HT
Remise'.$fac->remise_percent.'%
TVA'.price($fac->total_tva).''.MAIN_MONNAIE.'
Total'.price($fac->total_ttc).''.MAIN_MONNAIE.' TTC
Note : '.nl2br($fac->note)."

"; if ($fac->brouillon == 1 && $user->rights->commande->creer) { print '
'; print ''; print '
Remise'; print '%'; print ''; print '
'; } /* * Lignes de commandes * */ $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent, l.subprice"; $sql .= " FROM llx_commandedet as l WHERE l.fk_commande = $facid ORDER BY l.rowid"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $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( $i); $var=!$var; print ""; if ($objp->fk_product > 0) { print ''; } else { print "\n"; } print ''; print ''; if ($objp->remise_percent > 0) { print '\n"; } else { print ''; } print '\n"; if ($fac->statut == 0 && $user->rights->commande->creer) { print ''; print ''; } else { print ''; } print ""; if ($action == 'editline' && $rowid == $objp->rowid) { print ""; print ''; print ''; print ""; print ''; print ''; print ''; print ''; print ''; print '' . "\n"; print "\n"; } $total = $total + ($objp->qty * $objp->price); $i++; } $db->free(); // print "
DescriptionTvaQuantitéRemiseP.U.  
'.stripslashes(nl2br($objp->description)).'".stripslashes(nl2br($objp->description))."'.$objp->tva_taux.' %'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice)."deledit  
 %
"; } else { print $db->error(); } /* * Ajouter une ligne * */ if ($fac->statut == 0 && $user->rights->commande->creer) { print "
"; // echo ''; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ""; } print "
DescriptionTvaQuantitéRemiseP.U.  
'; print $html->select_tva("tva_tx"); print ' %
"; /* * Fin Ajout ligne * */ if ($user->societe_id == 0) { print '

'; if ($fac->statut == 0 && $user->rights->commande->supprimer) { print ""; } elseif ($fac->statut == 1 && abs($resteapayer) > 0 && $user->rights->commande->envoyer) { print ""; } else { print ""; } if ($fac->statut == 1 && $resteapayer > 0 && $user->rights->commande->paiement) { print ""; } else { print ""; } if ($fac->statut == 1 && abs($resteapayer) == 0 && $fac->paye == 0) { if ($user->rights->commande->paiement) { print ""; } else { print ''; } } elseif ($fac->statut == 1 && $resteapayer > 0 && $user->rights->commande->envoyer) { print ""; } else { print ''; } if ($fac->statut == 0 && $fac->total_ht > 0) { if ($user->rights->commande->valider) { print ""; } else { print ''; } } elseif ($fac->statut == 1 && $fac->paye == 0) { if ($user->rights->commande->creer) { print ""; } else { print ''; } } else { print ''; } if ($fac->statut > 0) { //print ''; print ''; } else { print ''; } print "
[Supprimer][Envoyer]-[Emettre un paiement]-[Classer 'Payée']-[Envoyer une relance]-[Valider]-Générer la commande---Récurrente-
"; } print "

\n"; /* * Documents générés * */ $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".pdf"; if (file_exists($file)) { print "
"; print_titre("Documents"); print ''; print ""; print ''; print ''; print ''; print ''; print "
Commande PDFref."/".$fac->ref.'.pdf">'.$fac->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
\n"; print '
'; print_titre("Actions"); /* * Liste des actions * */ $sql = "SELECT ".$db->pdate("a.datea")." as da, a.note"; $sql .= " FROM llx_actioncomm as a WHERE a.fk_soc = $fac->socidp AND a.fk_action in (9,10) AND a.fk_commande = $facid"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); if ($num) { $i = 0; $total = 0; print ''; print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object( $i); $var=!$var; print ""; print "\n"; print ''; print ""; $i++; } print "
DateAction
".strftime("%d %B %Y",$objp->da)."'.stripslashes($objp->note).'
"; } } else { print $db->error(); } /* * * */ print "
"; } /* * * */ if ($action == 'classer') { print "

\n"; print ''; print ''; print '"; print '
Projet'; $proj = new Project($db); $html->select_array("projetid",$proj->liste_array($socidp)); print "

'; } /* * * */ if ($action == 'presend') { $replytoname = $user->fullname; $from_name = $replytoname; $replytomail = $user->email; $from_mail = $replytomail; print "
\n"; print ''; print ''; print "

Envoyer la commande par mail"; print ""; print '"; print ""; print ""; print "
Destinataire'; $form = new Form($db); $form->select_array("destinataire",$soc->contact_email_array()); print "email\">
Expéditeur$from_name$from_mail
Reply-to$replytoname$replytomail
"; print "

"; } if ($action == 'prerelance') { $replytoname = $user->fullname; $from_name = $replytoname; $replytomail = $user->email; $from_mail = $replytomail; print "
\n"; print ''; print ''; print ''; print_titre("Envoyer une relance"); print ""; print '"; print ""; print ""; print "
Destinataire'; $form = new Form($db); $form->select_array("destinataire",$soc->contact_email_array()); print "email\">
Expéditeur$from_name$from_mail
Reply-to$replytoname$replytomail
"; print "
"; } /* * Propales */ $sql = "SELECT ".$db->pdate("p.datep")." as dp, p.price, p.ref, p.rowid as propalid"; $sql .= " FROM llx_propal as p, llx_fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_commande = $facid"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); if ($num) { $i = 0; $total = 0; print "

"; if ($num >1) { print_titre("Propositions commerciales associées"); } else { print_titre("Proposition commerciale associée"); } print ''; print ''; print ""; print ""; print ''; print "\n"; $var=True; while ($i < $num) { $objp = $db->fetch_object( $i); $var=!$var; print ""; print "\n"; print "\n"; print ''; print ""; $total = $total + $objp->price; $i++; } print "\n"; print "
NuméroDatePrix
propalid\">$objp->ref".strftime("%d %B %Y",$objp->dp)."'.price($objp->price).'
Total : ".price($total)." $_MONNAIE HT
"; } } else { print $db->error(); } } else { /* Commande non trouvée */ print "Commande inexistante ou accés refusé"; } } else { /*************************************************************************** * * * Mode Liste * * * * * ***************************************************************************/ } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>