2
0
forked from Wavyzz/dolibarr

Merge pull request #759 from cbattarel/contrat_propal

can now create contract from signed propal
This commit is contained in:
Laurent Destailleur
2013-03-19 19:26:54 -07:00
3 changed files with 2459 additions and 2258 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -649,14 +649,16 @@ class Contrat extends CommonObject
// Insert contract
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec, fk_soc, fk_user_author, date_contrat,";
$sql.= " fk_commercial_signature, fk_commercial_suivi, fk_projet,";
$sql.= " ref, entity)";
$sql.= " ref, entity, note, note_public)";
$sql.= " VALUES (".$this->db->idate($now).",".$this->socid.",".$user->id;
$sql.= ",".$this->db->idate($this->date_contrat);
$sql.= ",".($this->commercial_signature_id>0?$this->commercial_signature_id:"NULL");
$sql.= ",".($this->commercial_suivi_id>0?$this->commercial_suivi_id:"NULL");
$sql.= ",".($this->fk_projet>0?$this->fk_projet:"NULL");
$sql.= ",".($this->fk_project>0?$this->fk_project:"NULL");
$sql.= ", ".(dol_strlen($this->ref)<=0 ? "null" : "'".$this->ref."'");
$sql.= ", ".$conf->entity;
$sql.= ", ".(!empty($this->note)?("'".$this->db->escape($this->note)."'"):"NULL");
$sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
$sql.= ")";
$resql=$this->db->query($sql);
if ($resql)
@@ -694,6 +696,12 @@ class Contrat extends CommonObject
if (! $error)
{
// Add linked object
if (! $error && $this->origin && $this->origin_id)
{
$ret = $this->add_object_linked();
if (! $ret) dol_print_error($this->db);
}
$this->db->commit();
return $this->id;
}

View File

@@ -176,27 +176,158 @@ if ($action == 'add' && $user->rights->contrat->creer)
if (! $error)
{
$object->socid = $socid;
$object->socid = $socid;
$object->date_contrat = $datecontrat;
$object->commercial_suivi_id = GETPOST('commercial_suivi_id','int');
$object->commercial_signature_id = GETPOST('commercial_signature_id','int');
$object->note = GETPOST('note','alpha');
$object->note_public = GETPOST('note_public','alpha');
$object->fk_project = GETPOST('projectid','int');
$object->remise_percent = GETPOST('remise_percent','alpha');
$object->ref = GETPOST('ref','alpha');
$result = $object->create($user,$langs,$conf);
if ($result > 0)
{
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
}
else {
$mesg='<div class="error">'.$object->error.'</div>';
}
$action='create';
// If creation from another object of another module (Example: origin=propal, originid=1)
if ($_POST['origin'] && $_POST['originid'])
{
// Parse element/subelement (ex: project_task)
$element = $subelement = $_POST['origin'];
if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs))
{
$element = $regs[1];
$subelement = $regs[2];
}
// For compatibility
if ($element == 'order') { $element = $subelement = 'commande'; }
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
$object->origin = $_POST['origin'];
$object->origin_id = $_POST['originid'];
// Possibility to add external linked objects with hooks
$object->linked_objects[$object->origin] = $object->origin_id;
if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects']))
{
$object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
}
$id = $object->create($user);
if ($id < 0) {
$mesg='<div class="error">'.$object->error.'</div>';
}
if ($id > 0)
{
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
$classname = ucfirst($subelement);
$srcobject = new $classname($db);
dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
$result=$srcobject->fetch($object->origin_id);
if ($result > 0)
{
$srcobject->fetch_thirdparty();
$lines = $srcobject->lines;
if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
$fk_parent_line=0;
$num=count($lines);
for ($i=0;$i<$num;$i++)
{
$product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
if ($product_type == 1) { //only services
// service prédéfini
if ($lines[$i]->fk_product > 0)
{
$product_static = new Product($db);
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
{
$prod = new Product($db, $lines[$i]->fk_product);
$outputlangs = $langs;
$newlang='';
if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
if (empty($newlang)) $newlang=$srcobject->client->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$label = (! empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label;
}
else
{
$label = $lines[$i]->product_label;
}
if ($conf->global->PRODUIT_DESC_IN_FORM)
$desc .= ($lines[$i]->desc && $lines[$i]->desc!=$lines[$i]->libelle)?dol_htmlentitiesbr($lines[$i]->desc):'';
}
else {
$desc = dol_htmlentitiesbr($lines[$i]->desc);
}
$result = $object->addline(
$desc,
$lines[$i]->subprice,
$lines[$i]->qty,
$lines[$i]->tva_tx,
$lines[$i]->localtax1_tx,
$lines[$i]->localtax2_tx,
$lines[$i]->fk_product,
$lines[$i]->remise_percent,
$date_start =0,
$date_end =0,
'HT',
0,
$lines[$i]->info_bits,
$lines[$i]->fk_fournprice,
$lines[$i]->pa_ht
);
if ($result < 0)
{
$error++;
break;
}
}
}
}
else
{
$mesg=$srcobject->error;
$error++;
}
}
else
{
$mesg=$object->error;
$error++;
}
}
else
{
$result = $object->create($user,$langs,$conf);
if ($result > 0)
{
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
}
else {
$mesg='<div class="error">'.$object->error.'</div>';
}
$action='create';
}
}
}
@@ -622,6 +753,51 @@ if ($action == 'create')
$soc = new Societe($db);
if ($socid>0) $soc->fetch($socid);
if (GETPOST('origin') && GETPOST('originid'))
{
// Parse element/subelement (ex: project_task)
$element = $subelement = GETPOST('origin');
if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs))
{
$element = $regs[1];
$subelement = $regs[2];
}
if ($element == 'project')
{
$projectid=GETPOST('originid');
}
else
{
// For compatibility
if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; }
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
$classname = ucfirst($subelement);
$objectsrc = new $classname($db);
$objectsrc->fetch(GETPOST('originid'));
if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines();
$objectsrc->fetch_thirdparty();
$projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:'');
$soc = $objectsrc->client;
$note_private = (! empty($objectsrc->note) ? $objectsrc->note : (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''));
$note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : '');
// Object source contacts list
$srccontactslist = $objectsrc->liste_contact(-1,'external',1);
}
}
else {
$projectid = GETPOST('projectid','int');
$note_private = GETPOST("note");
$note_public = GETPOST("note_public");
}
$object->date_contrat = dol_now();
$numct = $object->getNextNumRef($soc);
@@ -687,18 +863,18 @@ if ($action == 'create')
if (! empty($conf->projet->enabled))
{
print '<tr><td>'.$langs->trans("Project").'</td><td>';
select_projects($soc->id,GETPOST("projectid"),"projectid");
select_projects($soc->id,$projectid,"projectid");
print "</td></tr>";
}
print '<tr><td>'.$langs->trans("NotePublic").'</td><td valign="top">';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('note_public', GETPOST('note_public'), '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, 70);
$doleditor=new DolEditor('note_public', $note_public, '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, 70);
print $doleditor->Create(1);
/*
print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">';
print GETPOST("note_public");
print $note_public;
print '</textarea></td></tr>';
*/
@@ -706,11 +882,11 @@ if ($action == 'create')
{
print '<tr><td>'.$langs->trans("NotePrivate").'</td><td valign="top">';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor=new DolEditor('note', GETPOST('note'), '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, 70);
$doleditor=new DolEditor('note', $note_private, '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, 70);
print $doleditor->Create(1);
/*
print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">';
print GETPOST("note");
print $note_private;
print '</textarea>';*/
print '</td></tr>';
}
@@ -721,6 +897,12 @@ if ($action == 'create')
print "</table>\n";
if (is_object($objectsrc))
{
print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
}
print '<br><center><input type="submit" class="button" value="'.$langs->trans("Create").'"></center>';
print "</form>\n";