add source of demand for propal

This commit is contained in:
Philippe Grand 2011-04-27 08:49:51 +00:00
parent bc3312aa3d
commit b8c149ac3b
4 changed files with 111 additions and 1 deletions

View File

@ -161,6 +161,11 @@ if ($_GET["action"] == 'create')
print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
$html->select_types_paiements($soc->mode_reglement,'mode_reglement_id');
print '</td></tr>';
// Source de propale
print '<tr><td>'.$langs->trans('Source').'</td><td>';
$html->select_demand_reason($soc->demand_reason,'demand_reason_id');
print '</td></tr>';
// delai de livraison
print '<tr><td>'.$langs->trans('AvailabilityPeriod').'</td><td colspan="2">';

View File

@ -6,6 +6,7 @@
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
*
* 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
@ -259,6 +260,7 @@ if ($_POST['action'] == 'add' && $user->rights->propale->creer)
$object->datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
$object->date_livraison = dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']);
$object->availability_id = $_POST['availability_id'];
$object->demand_reason_id = $_POST['demand_reason_id'];
$object->fk_delivery_address = $_POST['fk_address'];
$object->duree_validite = $_POST['duree_validite'];
$object->cond_reglement_id = $_POST['cond_reglement_id'];
@ -287,6 +289,7 @@ if ($_POST['action'] == 'add' && $user->rights->propale->creer)
$object->datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
$object->date_livraison = dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']);
$object->availability_id = $_POST['availability_id'];
$object->demand_reason_id = $_POST['demand_reason_id'];
$object->fk_delivery_address = $_POST['fk_address'];
$object->duree_validite = $_POST['duree_validite'];
$object->cond_reglement_id = $_POST['cond_reglement_id'];
@ -894,6 +897,14 @@ if ($_POST["action"] == 'setavailability')
$_GET['id']=$_REQUEST['id'];
}
// Origine de la propale
if ($_POST["action"] == 'setdemandreason')
{
$object->fetch($_REQUEST['id']);
$result = $object->demand_reason($_POST['demand_reason_id']);
$_GET['id']=$_REQUEST['id'];
}
// Conditions de reglement
if ($_POST["action"] == 'setconditions')
{
@ -1119,7 +1130,7 @@ if ($id > 0 || ! empty($ref))
print '</td>';
print '</tr>';
$rowspan=10;
$rowspan=11;
// Company
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="5">'.$soc->getNomUrl(1).'</td>';
@ -1299,6 +1310,26 @@ if ($id > 0 || ! empty($ref))
$html->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none');
}
print '</td>';
print '</tr>';
// Origine de la demande
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Source');
print '</td>';
if ($_GET['action'] != 'editdemandreason' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDemandReason'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="3">';
if ($_GET['action'] == 'editdemandreason')
{
$html->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id');
}
else
{
$html->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none');
}
print '</td>';
print '</tr>';

View File

@ -7,6 +7,7 @@
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
*
* 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
@ -97,6 +98,8 @@ class Propal extends CommonObject
var $adresse;
var $availability_id;
var $availability_code;
var $demand_reason_id;
var $demand_reason_code;
var $products=array();
@ -631,6 +634,7 @@ class Propal extends CommonObject
$sql.= ", ref_client";
$sql.= ", date_livraison";
$sql.= ", fk_availability";
$sql.= ", fk_demand_reason";
$sql.= ", entity";
$sql.= ") ";
$sql.= " VALUES (";
@ -654,6 +658,7 @@ class Propal extends CommonObject
$sql.= ", '".$this->db->escape($this->ref_client)."'";
$sql.= ", ".($this->date_livraison!=''?"'".$this->db->idate($this->date_livraison)."'":'null');
$sql.= ", ".$this->availability_id;
$sql.= ", ".$this->demand_reason_id;
$sql.= ", ".$conf->entity;
$sql.= ")";
@ -954,6 +959,7 @@ class Propal extends CommonObject
$sql.= ", fk_user_author, fk_user_valid, fk_user_cloture";
$sql.= ", fk_adresse_livraison";
$sql.= ", p.fk_availability";
$sql.= ", p.fk_demand_reason";
$sql.= ", p.fk_cond_reglement";
$sql.= ", p.fk_mode_reglement";
$sql.= ", c.label as statut_label";
@ -963,6 +969,7 @@ class Propal extends CommonObject
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON p.fk_availability = ca.rowid';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_demand_reason as dr ON p.fk_demand_reason = dr.rowid';
$sql.= " WHERE p.fk_statut = c.id";
$sql.= " AND p.entity = ".$conf->entity;
if ($ref) $sql.= " AND p.ref='".$ref."'";
@ -1006,6 +1013,9 @@ class Propal extends CommonObject
$this->availability_id = $obj->fk_availability;
$this->availability_code = $obj->availability_code;
$this->availability = $obj->availability;
$this->demand_reason_id = $obj->fk_demand_reason;
$this->demand_reason_code = $obj->demand_reason_code;
$this->demand_reason = $obj->demand_reason;
$this->fk_delivery_address = $obj->fk_adresse_livraison; // TODO obsolete
$this->fk_address = $obj->fk_adresse_livraison;
@ -1307,6 +1317,34 @@ class Propal extends CommonObject
}
}
/**
* \brief Set source of demand
* \param user Objet utilisateur qui modifie
* \param demand_reason source of demand
* \return int <0 si ko, >0 si ok
*/
function set_demand_reason($user, $id)
{
if ($user->rights->propale->creer)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."propal ";
$sql.= " SET fk_demand_reason = '".$id."'";
$sql.= " WHERE rowid = ".$this->id;
if ($this->db->query($sql))
{
$this->fk_demand_reason = $id;
return 1;
}
else
{
$this->error=$this->db->error();
dol_syslog("Propal::set_demand_reason Erreur SQL");
return -1;
}
}
}
/**
* \brief Positionne numero reference client
* \param user Utilisateur qui modifie
@ -1858,6 +1896,39 @@ class Propal extends CommonObject
return -2;
}
}
/**
* \brief Change l'origine de la demande
* \param demand_reason_id Id de la nouvelle origine de demande
* \return int >0 si ok, <0 si ko
*/
function demand_reason($demand_reason_id)
{
dol_syslog('Propale::demand_reason('.$demand_reason_id.')');
if ($this->statut >= 0)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'propal';
$sql .= ' SET fk_demand_reason = '.$demand_reason_id;
$sql .= ' WHERE rowid='.$this->id;
if ( $this->db->query($sql) )
{
$this->demand_reason_id = $demand_reason_id;
return 1;
}
else
{
dol_syslog('Propale::demand_reason Erreur '.$sql.' - '.$this->db->error());
$this->error=$this->db->error();
return -1;
}
}
else
{
dol_syslog('Propale::demand_reason, etat propale incompatible');
$this->error='Etat propale incompatible '.$this->statut;
return -2;
}
}
/**
@ -2078,6 +2149,8 @@ class Propal extends CommonObject
$this->mode_reglement_code = 'CHQ';
$this->availability_id = 1;
$this->availability_code = 'DSP';
$this->demand_reason_id = 1;
$this->demand_reason_code = 'SRC_00';
$this->note_public='This is a comment (public)';
$this->note='This is a comment (private)';
// Lines

View File

@ -16,6 +16,7 @@ RENAME TABLE llx_c_source TO llx_c_demand_reason;
ALTER TABLE llx_adherent MODIFY login varchar(50);
ALTER TABLE llx_c_actioncomm ADD COLUMN position integer NOT NULL DEFAULT 0;
ALTER TABLE llx_propal ADD COLUMN fk_demand_reason integer NULL DEFAULT 0;
ALTER TABLE llx_commande_fournisseur MODIFY model_pdf varchar(255);
ALTER TABLE llx_commande MODIFY model_pdf varchar(255);