Skip to content

Instantly share code, notes, and snippets.

@rodrigobravo
Created September 29, 2017 02:22
Show Gist options
  • Select an option

  • Save rodrigobravo/8606d2f8b1ecff7e1ae51327cae7cea7 to your computer and use it in GitHub Desktop.

Select an option

Save rodrigobravo/8606d2f8b1ecff7e1ae51327cae7cea7 to your computer and use it in GitHub Desktop.
<?php
include_once 'Class.php';
include_once 'querys.php';
try{
$db = new PDO('sqlite:/home/rodrigo/delivery2/files/database.db');
if(!$db){
echo $db->lastErrorMsg() ;
}else{
$sql = $db->prepare($sqlPedidos);
$listaPedidos = array();
$sql->execute();
while ($row = $sql->fetchObject()){
$linhas[] = $row;
$today=date('d-m-Y');
var_dump($row);
foreach ($linhas as $entrada) {
var_dump($entrada);
$reqdate = $entrada->date_req;
if ($today === $reqdate){
$clock = datetime::createFromFormat( 'U', (substr($entrada->clock_req,0,-9)));
$novoPedido = new Pedido($entrada->id, $entrada->doc_prefix, $entrada->doc_number, $entrada->acumulador, $entrada->date_req, $clock->format("H:i"), $entrada->client_id, $entrada->cliente, $entrada->Address, $entrada->funcionario, $entrada->local, $entrada->obs, $entrada->total);
$listaPedidos[] = $novoPedido;
}
}
if (empty($listaPedidos)){
}
}
}
}
catch(PDOException $e){
print 'Exception1 : '.$e->getMessage();
}
try{
$dbdest = new PDO('sqlite:/home/rodrigo/delivery2/files/delivery.db');
$dbdest->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(!$dbdest){
echo $dbdest->lastErrorMsg() ;
}else{
foreach ($listaPedidos as $key) {
$sqlinsert = $dbdest->prepare($sqlInsertRequests);
$sqlinsertclients = $dbdest->prepare($sqlInsertClients);
$client_id = $key->client_id;
$client_name = $key->client_name;
$address = $key->address;
$funcionario = $key->employee_name;
$acumulador = $key->accumulator;
$obs = $key->obs;
$total = $key->total_price;
$date_req = $key->date;
$id = $key->id_orig;
$doc_number = $key->doc_number;
$clock_req = $key->clock;
$sqlinsert->bindParam(':client_id', $client_id);
$sqlinsert->bindParam(':employee_name', $funcionario);
$sqlinsert->bindParam(':accumulator', $acumulador);
$sqlinsert->bindParam(':obs1', $obs);
$sqlinsert->bindParam(':totalPrice', $total);
$sqlinsert->bindParam(':date1', $date_req);
$sqlinsert->bindParam(':id_orig', $id);
$sqlinsert->bindParam(':doc_number', $doc_number);
$sqlinsert->bindParam(':clock_req', $clock_req);
$sqlinsertclients->bindParam(':id_orig', $client_id);
$sqlinsertclients->bindParam(':name', $client_name);
$sqlinsertclients->bindParam(':address', $address);
$sqlinsertclients->bindParam(':obs', $obs);
//fill products
$sqlproduct = $db->prepare($sqlProdutos);
$sqlproduct->bindParam(':id_orig', $id);
$sqlproduct->execute();
while ($rowp = $sqlproduct->fetchObject()){
$linhasp[] = $rowp;
$listaProdutos = array();
foreach ($linhasp as $entradap) {
$novoProduto = new Product($entradap->id, $entradap->docheader_id, $entradap->description, $entradap->qnt, $entradap->price, $entradap->discount_value, $entradap->total, $entradap->gross_total, $entradap->line_number);
$listaProdutos[] = $novoProduto;
}
foreach ($listaProdutos as $prod_fill) {
$sqlinsertp = $dbdest->prepare($sqlInsertProducts);
//var_dump($prod_fill);
$orig_id = $prod_fill->orig_id;
$requests_id = $prod_fill->requests_id;
$name = $prod_fill->name;
$qnt = $prod_fill->qnt;
$price = $prod_fill->price;
$discount_value = $prod_fill->discount_value;
$total = $prod_fill->total;
$gross_total = $prod_fill->gross_total;
$line = $prod_fill->line;
$sqlinsertp->bindParam(':orig_id', $orig_id);
$sqlinsertp->bindParam(':requests_id', $requests_id);
$sqlinsertp->bindParam(':name', $name);
$sqlinsertp->bindParam(':qnt', $qnt);
$sqlinsertp->bindParam(':price', $price);
$sqlinsertp->bindParam(':discount_value', $discount_value);
$sqlinsertp->bindParam(':total', $total);
$sqlinsertp->bindParam(':gross_total', $gross_total);
$sqlinsertp->bindParam(':line', $line);
$sqlinsertp->execute();
}
}
$sqlinsert->execute();
$sqlinsertclients->execute();
}
}
}
catch(PDOException $f){
print 'Exception2 : '.$f->getMessage();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment