function saveDjai($djai) { $query = "SELECT * FROM djais d WHERE d.number = '" . $djai->number . "'"; $result = mysql_query($query); $num_results = mysql_num_rows($result); $rows = fetch_array($result); $obj->successful = false; $obj->isNew = false; if ($num_results != 0) { // update (no fields for the moment to update) // if(mysql_query($update)) $obj->successful = true; } else { // insert foreach ($djai->cloths as $cloth) { $insert = "INSERT INTO djais VALUES ('" . $cloth->djaiId . "', '" . $djai->number . "', curdate(), '" . $cloth->amount . "', '" . $cloth->id . "')"; if (mysql_query($insert)) { $obj->successful = true; $obj->isNew = true; } } } if ($obj->successful && !$obj->isNew) { handleCloths($djai, $rows, $obj); } $obj->djai = $djai; return $obj; }
function savePrevision($prevision) { $query = "SELECT * FROM previsions p LEFT JOIN previsioncloth pc on p.id = pc.previsionId WHERE p.id = '" . $prevision->id . "'"; $result = mysql_query($query); $num_results = mysql_num_rows($result); $rows = fetch_array($result); $obj->method = 'savePrevision'; $obj->successful = false; $observations = isset($prevision->observations) ? $prevision->observations : ''; $productionObservations = isset($prevision->productionObservations) ? $prevision->productionObservations : ''; $designObservations = isset($prevision->designObservations) ? $prevision->designObservations : ''; $boat = isset($prevision->boat) ? $prevision->boat : ''; $client = isset($prevision->client) ? $prevision->client : ''; $sailId = isset($prevision->sailId) && $prevision->sailId != '' ? $prevision->sailId : 'null'; $sailGroupId = isset($prevision->sailGroupId) && $prevision->sailGroupId != '' ? $prevision->sailGroupId : 'null'; $sailDescription = isset($prevision->sailDescription) && $prevision->sailDescription != '' ? "'" . $prevision->sailDescription . "'" : 'null'; $sailOneDesign = isset($prevision->sailOneDesign) ? "'" . $prevision->sailOneDesign . "'" : 'null'; $oneDesign = $prevision->oneDesign == 1 ? 'true' : 'false'; $greaterThan44 = $prevision->greaterThan44 == 1 ? 'true' : 'false'; $p = isset($prevision->p) && trim($prevision->p) != '' ? $prevision->p : 'null'; $e = isset($prevision->e) && trim($prevision->e) != '' ? $prevision->e : 'null'; $i = isset($prevision->i) && trim($prevision->i) != '' ? $prevision->i : 'null'; $j = isset($prevision->j) && trim($prevision->j) != '' ? $prevision->j : 'null'; $area = isset($prevision->area) && trim($prevision->area) != '' ? $prevision->area : 'null'; $rizo = isset($prevision->rizo) && trim($prevision->rizo) != '' ? $prevision->rizo : 'null'; $country = isset($prevision->country) && trim($prevision->country) != '' ? $prevision->country : 'ARG'; $week = isset($prevision->week) && trim($prevision->week) != '' ? $prevision->week : 'null'; $priority = isset($prevision->priority) && trim($prevision->priority) != '' ? $prevision->priority : 'null'; $line = isset($prevision->line) && trim($prevision->line) != '' ? "'" . $prevision->line . "'" : 'null'; $seller = isset($prevision->seller) && trim($prevision->seller) != '' ? "'" . $prevision->seller . "'" : 'null'; $advance = isset($prevision->advance) && trim($prevision->advance) != '' ? $prevision->advance : 'null'; $percentage = isset($prevision->percentage) && trim($prevision->percentage) != '' ? $prevision->percentage : 'null'; $tentativeDate = isset($prevision->tentativeDate) && trim($prevision->tentativeDate) != '' ? "STR_TO_DATE('" . $prevision->tentativeDate . "', '%d-%m-%Y')" : 'null'; $productionDate = isset($prevision->productionDate) && trim($prevision->productionDate) != '' ? "STR_TO_DATE('" . $prevision->productionDate . "', '%d-%m-%Y')" : 'null'; $infoDate = isset($prevision->infoDate) && trim($prevision->infoDate) != '' ? "STR_TO_DATE('" . $prevision->infoDate . "', '%d-%m-%Y')" : 'null'; $advanceDate = isset($prevision->advanceDate) && trim($prevision->advanceDate) != '' ? "STR_TO_DATE('" . $prevision->advanceDate . "', '%d-%m-%Y')" : 'null'; $dispatchId = isset($prevision->dispatchId) && trim($prevision->dispatchId) != '' ? "'" . $prevision->dispatchId . "'" : 'null'; if ($num_results != 0) { logPrevisionUpdateFull($prevision->id, 'savePrevision'); // update $update = "UPDATE previsions SET orderNumber = '" . $prevision->orderNumber . "', deliveryDate = STR_TO_DATE('" . $prevision->deliveryDate . "', '%d-%m-%Y'), client = '" . $client . "', sailId = {$sailId}, sailGroupId = {$sailGroupId}, sailDescription = {$sailDescription}, boat = '" . $boat . "', type = '" . $prevision->type . "', oneDesign = " . $oneDesign . ", greaterThan44 = " . $greaterThan44 . ", p = " . $p . ", e = " . $e . ", i = " . $i . ", j = " . $j . ", area = " . $area . ", sailOneDesign = {$sailOneDesign}, observations = '{$observations}'" . ", productionObservations = '{$productionObservations}', designObservations = '{$designObservations}', dispatchId = {$dispatchId}" . ", week = {$week}, priority = {$priority}, line = {$line}, seller = {$seller}, advance = {$advance}, percentage = {$percentage}" . ", tentativeDate = {$tentativeDate}, productionDate = {$productionDate}, infoDate = {$infoDate}, advanceDate = {$advanceDate}, rizo = {$rizo}, country = '{$country}'" . " WHERE id = '" . $prevision->id . "'"; if (mysql_query($update)) { $obj->successful = true; } else { $obj->successfulUpdate = false; $obj->update = $update; } } else { // insert $insert = "INSERT INTO previsions (id, orderNumber, deliveryDate, client, sailId, sailGroupId, sailDescription, boat,\n\t\t\t\ttype, designed, oneDesign, greaterThan44, p, e, i,j, area, sailOneDesign, observations, productionObservations, designObservations,\n\t\t\t\tweek, priority, line, seller, advance, percentage, tentativeDate, productionDate, infoDate, advanceDate, dispatchId, rizo, country)\n\t\t\t\tVALUES ('" . $prevision->id . "', '" . $prevision->orderNumber . "', STR_TO_DATE('" . $prevision->deliveryDate . "', '%d-%m-%Y'), '" . $client . "', {$sailId}, {$sailGroupId}, {$sailDescription}, '" . $boat . "', '" . $prevision->type . "', false, " . $oneDesign . ", " . $greaterThan44 . ", " . $p . ", " . $e . ", " . $i . ", " . $j . ", " . $area . ", {$sailOneDesign}, '{$observations}', '{$productionObservations}', '{$designObservations}',\n\t\t\t\t\t\t\t\t{$week}, {$priority}, {$line}, {$seller}, {$advance}, {$percentage}, {$tentativeDate}, {$productionDate}, {$infoDate}, {$advanceDate}, {$dispatchId}, {$rizo}, '{$country}')"; if (mysql_query($insert)) { $obj->successful = true; $obj->isNew = true; } else { $obj->successfulInsert = false; $obj->insert = $insert; } } if ($obj->successful) { handleCloths($prevision, $rows, $obj); } $obj->prevision = $prevision; return $obj; }