diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index d1f42ddc371..aa66bde3aa9 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -1,6 +1,5 @@ - * Copyright (C) 2003 Éric Seigne * * 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 @@ -21,81 +20,134 @@ * */ -class Commande { +class Commande +{ var $db ; - var $id ; - var $client_name ; - - Function Commande($DB, $id=0) { - $this->db = $DB; - $this->id = $id ; - } - /* - * - * - * - */ - Function fetch ($id) { - - $sql = "SELECT o.orders_id, o.customers_name, o.orders_status FROM ".DB_NAME_OSC.".orders as o"; - - $sql .= " WHERE o.orders_id = $id"; - - $result = $this->db->query($sql) ; - - if ( $result ) { - $result = $this->db->fetch_array(); - - $this->id = $result["rowid"]; - $this->client_name = $result["customers_name"]; - - $this->nom_url = ''.$result["nom"].''; + var $brouillon; + Function Commande($DB) + { + $this->db = $DB; } - $this->db->free(); + /** + * Créé la facture depuis une propale existante + * + * + */ + Function create_from_propale($user, $propale_id) + { + $this->propale_id = $propale_id; + return $this->create($user); + } + /** + * Créé la facture + * + * + */ + Function create($user) + { + /* On positionne en mode brouillon la facture */ + $this->brouillon = 1; - return $result; - } + if (! $remise) + { + $remise = 0 ; + } + + if (! $this->projetid) + { + $this->projetid = 0; + } + + $sql = "INSERT INTO llx_commande (fk_soc, date_creation, fk_user_author,fk_projet) "; + $sql .= " VALUES ($socid, now(), $user->id, $this->projetid)"; + if ( $this->db->query($sql) ) + { + $this->id = $this->db->last_insert_id(); + + $sql = "UPDATE llx_commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; + $this->db->query($sql); + + if ($this->id && $this->propale_id) + { + $sql = "INSERT INTO llx_co_pr (fk_commande, fk_propale) VALUES (".$this->id.",".$this->propale_id.")"; + $this->db->query($sql); + } + /* + * Produits + * + */ + for ($i = 0 ; $i < sizeof($this->products) ; $i++) + { + $prod = new Product($this->db, $this->products[$i]); + $prod->fetch($this->products[$i]); + + $result_insert = $this->addline($this->id, + $prod->libelle, + $prod->price, + $this->products_qty[$i], + $prod->tva_tx, + $this->products[$i], + $this->products_remise_percent[$i]); + + + if ( $result_insert < 0) + { + print $sql . '
' . $this->db->error() .'
'; + } + } + + /* + * + * + */ + $this->updateprice($this->id); + return $this->id; + } + else + { + print $this->db->error() . '
'.$sql; + return 0; + } + } + /** + * + * Lit une commande + * + */ + Function fetch ($id) + { + $sql = "SELECT c.rowid, c.date, c.fk_user_author FROM commande as c"; + $sql .= " WHERE c.rowid = $id"; + + $result = $this->db->query($sql) ; + + if ( $result ) + { + $result = $this->db->fetch_object(); + + $this->id = $obj->rowid; + + $this->db->free(); + + return 1; + + } + else + { + return -1; + } + } /* * * */ - Function liste_products () - { - $ga = array(); - - $sql = "SELECT a.rowid, a.title FROM llx_album as a, llx_album_to_groupart as l"; - $sql .= " WHERE a.rowid = l.fk_album AND l.fk_groupart = ".$this->id; - $sql .= " ORDER BY a.title"; - - if ($this->db->query($sql) ) - { - $nump = $this->db->num_rows(); - - if ($nump) - { - $i = 0; - while ($i < $nump) - { - $obj = $this->db->fetch_object($i); - - $ga[$obj->rowid] = $obj->title; - $i++; - } - } - return $ga; - } - else - { - print $this->db->error(); - } - } - /* - * - * - */ - - } + +class CommandeLigne +{ + var $pu; +} + ?> diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 0b24ed70bd3..0b5c41a7818 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -19,52 +19,1096 @@ * $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(); -if ($id) +/* + * 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); - $result = $commande->fetch($id); - - if ( $result ) - { - print '
Fiche Commande

'; - - print ''; - print ""; - print "\n"; - print ""; - - - print "
Client$commande->client_name
Description".nl2br($commande->description)."
"; - } - + $commande->fetch($facid); + $commande->classin($HTTP_POST_VARS["projetid"]); } -else +/* + * + */ +if ($HTTP_POST_VARS["action"] == 'add') { - print "Error"; + $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 = ''; } +/* + * + */ -/* ************************************************************************** */ -/* */ -/* Barre d'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); + } +} -print '
'; -print ''; -print ''; -print ''; -print ''; -print ''; -print '
-----

'; +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(); diff --git a/htdocs/commande/index.php b/htdocs/commande/index.php index d4853377aee..db163e9dd89 100644 --- a/htdocs/commande/index.php +++ b/htdocs/commande/index.php @@ -24,20 +24,27 @@ require("./pre.inc.php"); llxHeader(); -if ($sortfield == "") { +print ''; + +print '
'; +/* + * + */ + + +if ($sortfield == "") +{ $sortfield="o.orders_status ASC, o.date_purchased"; } -if ($sortorder == "") { +if ($sortorder == "") +{ $sortorder="DESC"; } - if ($page == -1) { $page = 0 ; } $limit = $conf->liste_limit; $offset = $limit * $page ; - - $sql = "SELECT o.orders_id, o.customers_name, o.orders_status FROM ".DB_NAME_OSC.".orders as o"; $sql .= " ORDER BY $sortfield $sortorder "; @@ -50,27 +57,69 @@ if ( $db->query($sql) ) print_barre_liste("Liste des Commandes",$page,$PHP_SELF,"",$sortfield,$sortorder,'',$num); $i = 0; - print "

"; - print "
"; + print '

'; + print '"; print ""; - print "\n"; + print "\n"; $var=True; while ($i < min($num,$limit)) { $objp = $db->fetch_object( $i); - $var=!$var; - print ""; - print "\n"; - print "\n"; - print "\n"; - $i++; - } + $var=!$var; + print ""; + print "\n"; + print "\n"; + print "\n"; + $i++; + } print "
'; print_liste_field_titre("Client",$PHP_SELF, "p.ref"); print "
orders_id\">$objp->customers_name$objp->orders_status
orders_id\">$objp->customers_name$objp->orders_status
"; $db->free(); } +/* + * + */ +print '

'; +/* + * Propales à facturer + */ +if ($user->comm > 0 && $conf->commercial ) +{ + $sql = "SELECT p.rowid, p.ref, s.nom, s.idp FROM llx_propal as p, llx_societe as s"; + $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = 2"; + if ($socidp) + { + $sql .= " AND p.fk_soc = $socidp"; + } + + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + if ($num) + { + $i = 0; + print ''; + print ""; + print ''; + + while ($i < $num) + { + $var=!$var; + $obj = $db->fetch_object($i); + print ""; + print ''; + $i++; + } + print "
'.translate("Propositions commerciales signées").'
rowid\">$obj->ref'.$obj->nom.'

"; + } + } +} + + + +print '
'; $db->close(); diff --git a/htdocs/commande/osccommande.class.php b/htdocs/commande/osccommande.class.php new file mode 100644 index 00000000000..74d66efe578 --- /dev/null +++ b/htdocs/commande/osccommande.class.php @@ -0,0 +1,99 @@ + + * Copyright (C) 2003 Éric Seigne + * + * 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$ + * + */ + +class OscCommande { + var $db ; + + var $id ; + var $client_name ; + + Function OscCommande($DB, $id=0) { + $this->db = $DB; + $this->id = $id ; + } + /* + * + * + * + */ + Function fetch ($id) + { + + $sql = "SELECT o.orders_id, o.customers_name, o.orders_status FROM ".DB_NAME_OSC.".orders as o"; + $sql .= " WHERE o.orders_id = $id"; + + $result = $this->db->query($sql) ; + + if ( $result ) + { + $result = $this->db->fetch_array(); + + $this->id = $result["rowid"]; + $this->client_name = $result["customers_name"]; + + $this->nom_url = ''.$result["nom"].''; + } + $this->db->free(); + + return $result; + } + /* + * + * + */ + Function liste_products () + { + $ga = array(); + + $sql = "SELECT a.rowid, a.title FROM llx_album as a, llx_album_to_groupart as l"; + $sql .= " WHERE a.rowid = l.fk_album AND l.fk_groupart = ".$this->id; + $sql .= " ORDER BY a.title"; + + if ($this->db->query($sql) ) + { + $nump = $this->db->num_rows(); + + if ($nump) + { + $i = 0; + while ($i < $nump) + { + $obj = $this->db->fetch_object($i); + + $ga[$obj->rowid] = $obj->title; + $i++; + } + } + return $ga; + } + else + { + print $this->db->error(); + } + } + /* + * + * + */ +} +?> diff --git a/mysql/tables/llx_co_pr.sql b/mysql/tables/llx_co_pr.sql new file mode 100644 index 00000000000..61d2332faa8 --- /dev/null +++ b/mysql/tables/llx_co_pr.sql @@ -0,0 +1,27 @@ +-- =================================================================== +-- Copyright (C) 2003 Rodolphe Quiedeville +-- +-- 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$ +-- =================================================================== + +create table llx_co_pr +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_commande integer, + fk_propale integer +); diff --git a/mysql/tables/llx_commande.sql b/mysql/tables/llx_commande.sql new file mode 100644 index 00000000000..ab4f402e52d --- /dev/null +++ b/mysql/tables/llx_commande.sql @@ -0,0 +1,49 @@ +-- =================================================================== +-- Copyright (C) 2003 Rodolphe Quiedeville +-- +-- 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$ +-- +-- =================================================================== + +create table llx_commande +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_soc integer, + fk_soc_contact integer, + fk_projet integer default 0, -- projet auquel est rattache la commande + ref varchar(30) NOT NULL, -- propal number + date_creation datetime, -- date de creation + date_valid datetime, -- date de validation + date_cloture datetime, -- date de cloture + date_commande date, -- date de la commande + fk_user_author integer, -- createur de la commande + fk_user_valid integer, -- valideur de la commande + fk_user_cloture integer, -- cloture de la propale signee ou non signee + source smallint NOT NULL, + fk_statut smallint default 0, + amount_ht real default 0, + remise_percent real default 0, + remise real default 0, + tva real default 0, + total_ht real default 0, + total_ttc real default 0, + note text, + model_pdf varchar(50), + UNIQUE INDEX (ref) +);