Plug avec les factures
This commit is contained in:
parent
ed4adccc07
commit
e06977a781
@ -28,198 +28,212 @@
|
|||||||
|
|
||||||
require ("../../../master.inc.php");
|
require ("../../../master.inc.php");
|
||||||
|
|
||||||
$title = "DEVEL TITLE";
|
$month = "10";
|
||||||
$desc = "Developpements en cours";
|
$year = "2005";
|
||||||
$userlid = 1;
|
|
||||||
|
|
||||||
if ($db->begin())
|
|
||||||
|
$sqls = "SELECT l.rowid,l.ligne,l.fk_commercial_suiv";
|
||||||
|
$sqls .= " FROM ".MAIN_DB_PREFIX."telephonie_facture as f,".MAIN_DB_PREFIX."telephonie_societe_ligne as l";
|
||||||
|
$sqls .= " WHERE l.rowid =f.fk_ligne AND f.cout_vente < f.fourn_montant";
|
||||||
|
$sqls .= " AND f.date ='".$year."-".$month."-01'";
|
||||||
|
|
||||||
|
$resqls = $db->query($sqls);
|
||||||
|
if ( $resqls )
|
||||||
{
|
{
|
||||||
$result = -1;
|
while ($obj = $db->fetch_object($resqls))
|
||||||
|
{
|
||||||
|
$title = "Marge négative ligne ".$obj->ligne." pour $month-$year";
|
||||||
|
$desc = "La facturation de la ligne ".$obj->ligne. " présente une marge négative en $month/$year";
|
||||||
|
$userlid = $obj->fk_commercial_suiv;
|
||||||
|
|
||||||
|
if ($db->begin())
|
||||||
$sql = "SELECT vtiger_id from ".MAIN_DB_PREFIX."vtiger_users";
|
|
||||||
$sql .= " WHERE fk_user =".$userlid.";";
|
|
||||||
$result = 1;
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
if ( $resql )
|
|
||||||
{
|
{
|
||||||
if ($row = $db->fetch_row($resql))
|
$result = -1;
|
||||||
|
|
||||||
|
$sql = "SELECT vtiger_id from ".MAIN_DB_PREFIX."vtiger_users";
|
||||||
|
$sql .= " WHERE fk_user =".$userlid.";";
|
||||||
|
$result = 1;
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ( $resql )
|
||||||
{
|
{
|
||||||
$user_id = $row[0];
|
if ($row = $db->fetch_row($resql))
|
||||||
$result = 0;
|
{
|
||||||
|
$user_id = $row[0];
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "Error user id missing\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "Error user id missing\n";
|
print "Error 7\n";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "Error 7\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ($result == 0)
|
||||||
if ($result == 0)
|
|
||||||
{
|
|
||||||
$sql = "UPDATE vtiger.crmentity_seq set id=LAST_INSERT_ID(id+1)";
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
if ( $resql )
|
|
||||||
{
|
|
||||||
$result = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "Error 1\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result == 0)
|
|
||||||
{
|
|
||||||
$sql = "SELECT user_name from vtiger.users where id =".$user_id.";";
|
|
||||||
$result = 1;
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
if ( $resql )
|
|
||||||
{
|
|
||||||
if ($row = $db->fetch_row($resql))
|
|
||||||
{
|
{
|
||||||
$username = $row[0];
|
$sql = "UPDATE vtiger.crmentity_seq set id=LAST_INSERT_ID(id+1)";
|
||||||
$result = 0;
|
$resql = $db->query($sql);
|
||||||
|
if ( $resql )
|
||||||
|
{
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "Error 1\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result == 0)
|
||||||
|
{
|
||||||
|
$sql = "SELECT user_name from vtiger.users where id =".$user_id.";";
|
||||||
|
$result = 1;
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ( $resql )
|
||||||
|
{
|
||||||
|
if ($row = $db->fetch_row($resql))
|
||||||
|
{
|
||||||
|
$username = $row[0];
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "Error 4 Missing id for $user_id\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "Error 5\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($result == 0)
|
||||||
|
{
|
||||||
|
$sql = "SELECT id from vtiger.crmentity_seq;";
|
||||||
|
$result = 1;
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
$tid = 0;
|
||||||
|
if ( $resql )
|
||||||
|
{
|
||||||
|
if ($row = $db->fetch_row($resql))
|
||||||
|
{
|
||||||
|
$tid = $row[0];
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "Error 2\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "Error 3\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result == 0 && $tid > 0)
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO vtiger.troubletickets (ticketid, parent_id, priority, product_id, severity, status, category, update_log, title, description, solution) values ";
|
||||||
|
$sql .= " (".$tid.", '', 'High', '', 'Major', 'Open', 'Big Problem','";
|
||||||
|
$sql .= strftime("%E %d %B %Y %H:%M:%S", time())." by dolibarr--//--Ticket created. Assigned to $username--//--'";
|
||||||
|
$sql .= ", '".$title."', '".$desc."', '')";
|
||||||
|
|
||||||
|
$result = 1;
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ( $resql )
|
||||||
|
{
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print $db->error()."\n";
|
||||||
|
print "$sql\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ($result == 0 && $tid > 0)
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO vtiger.crmentity ";
|
||||||
|
$sql .= " (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) ";
|
||||||
|
$sql .= " VALUES ('".$tid."','$user_id','$user_id','HelpDesk','".$desc."',now(),now())";
|
||||||
|
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
$result = 1;
|
||||||
|
if ( $resql )
|
||||||
|
{
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print $db->error()."\n";
|
||||||
|
print "$sql\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result == 0 && $tid > 0)
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO vtiger.ticketcf (ticketid) values ($tid)";
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
$result = 1;
|
||||||
|
if ( $resql )
|
||||||
|
{
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result == 0 )
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO vtiger.ticketcomments (ticketid, comments) values ($tid, '')";
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
$result = 1;
|
||||||
|
if ( $resql )
|
||||||
|
{
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result == 0 )
|
||||||
|
{
|
||||||
|
$sql = "DELETE from vtiger.tracker WHERE user_id='$user_id' and item_id='$tid'";
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
$result = 1;
|
||||||
|
if ( $resql )
|
||||||
|
{
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result == 0 )
|
||||||
|
{
|
||||||
|
$sql = "INSERT INTO vtiger.tracker ";
|
||||||
|
$sql .= " (user_id, module_name, item_id, item_summary) values ";
|
||||||
|
$sql .= " ('".$user_id."', 'HelpDesk', '".$tid."', 'Test pour dev')";
|
||||||
|
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
$result = 1;
|
||||||
|
if ( $resql )
|
||||||
|
{
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result == 0)
|
||||||
|
{
|
||||||
|
$db->commit();
|
||||||
|
print "COMMIT $tid\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "Error 4\n";
|
$db->rollback();
|
||||||
|
print "ROLLBACK $tid\n";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "Error 5\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($result == 0)
|
|
||||||
{
|
|
||||||
$sql = "SELECT id from vtiger.crmentity_seq;";
|
|
||||||
$result = 1;
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$tid = 0;
|
|
||||||
if ( $resql )
|
|
||||||
{
|
|
||||||
if ($row = $db->fetch_row($resql))
|
|
||||||
{
|
|
||||||
$tid = $row[0];
|
|
||||||
$result = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "Error 2\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "Error 3\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result == 0 && $tid > 0)
|
|
||||||
{
|
|
||||||
$sql = "INSERT INTO vtiger.troubletickets (ticketid, parent_id, priority, product_id, severity, status, category, update_log, title, description, solution) values ";
|
|
||||||
$sql .= " (".$tid.", '', 'High', '', 'Major', 'Open', 'Big Problem','";
|
|
||||||
$sql .= strftime("%E %d %B %Y %H:%M:%S", time())." by dolibarr--//--Ticket created. Assigned to $username--//--'";
|
|
||||||
$sql .= ", '".$title."', '".$desc."', '')";
|
|
||||||
|
|
||||||
$result = 1;
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
if ( $resql )
|
|
||||||
{
|
|
||||||
$result = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print $db->error()."\n";
|
|
||||||
print "$sql\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($result == 0 && $tid > 0)
|
|
||||||
{
|
|
||||||
$sql = "INSERT INTO vtiger.crmentity ";
|
|
||||||
$sql .= " (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) ";
|
|
||||||
$sql .= " VALUES ('".$tid."','$user_id','$user_id','HelpDesk','".$desc."',now(),now())";
|
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$result = 1;
|
|
||||||
if ( $resql )
|
|
||||||
{
|
|
||||||
$result = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print $db->error()."\n";
|
|
||||||
print "$sql\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result == 0 && $tid > 0)
|
|
||||||
{
|
|
||||||
$sql = "INSERT INTO vtiger.ticketcf (ticketid) values ($tid)";
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$result = 1;
|
|
||||||
if ( $resql )
|
|
||||||
{
|
|
||||||
$result = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result == 0 )
|
|
||||||
{
|
|
||||||
$sql = "INSERT INTO vtiger.ticketcomments (ticketid, comments) values ($tid, '')";
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$result = 1;
|
|
||||||
if ( $resql )
|
|
||||||
{
|
|
||||||
$result = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result == 0 )
|
|
||||||
{
|
|
||||||
$sql = "DELETE from vtiger.tracker WHERE user_id='$user_id' and item_id='$tid'";
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$result = 1;
|
|
||||||
if ( $resql )
|
|
||||||
{
|
|
||||||
$result = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result == 0 )
|
|
||||||
{
|
|
||||||
$sql = "INSERT INTO vtiger.tracker ";
|
|
||||||
$sql .= " (user_id, module_name, item_id, item_summary) values ";
|
|
||||||
$sql .= " ('".$user_id."', 'HelpDesk', '".$tid."', 'Test pour dev')";
|
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
|
||||||
$result = 1;
|
|
||||||
if ( $resql )
|
|
||||||
{
|
|
||||||
$result = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result == 0)
|
|
||||||
{
|
|
||||||
$db->commit();
|
|
||||||
print "COMMIT $tid\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$db->rollback();
|
|
||||||
print "ROLLBACK $tid\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user