BillSync.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. require_once("DataBase_Net/Bill_Net.php");
  3. require_once("DataBase_Net/Bill_Product_Net.php");
  4. require_once("DataBase/Bill.php");
  5. require_once("DataBase/Bill_Product.php");
  6. // sync Bill database
  7. $bill = new Bill();
  8. $bill_net = new Bill_Net();
  9. $bill_product = new Bill_Product();
  10. $bill_product_net = new Bill_Product_Net();
  11. $new_bills_count = 0;
  12. $new_position_count = 0;
  13. // fetch all remote bills
  14. $remote_bills = $bill_net->getPlainBills();
  15. foreach($remote_bills as $tmp)
  16. {
  17. $new_bill_id = $bill->create("", array_slice($tmp, 1));
  18. $new_bills_count++;
  19. // check for bill_products
  20. $remote_bill_products = $bill_product_net->getByBillId($tmp[0]);
  21. foreach($remote_bill_products as $tmp1)
  22. {
  23. $tmp1[1] = $new_bill_id;
  24. $bill_product->create(array_slice($tmp1, 1));
  25. $new_position_count++;
  26. }
  27. }
  28. $main_box->add(new NTKLabel("", "neue Rechnungen: ".$new_bills_count), 200, 0, "background-color: #dfe7f3;");
  29. $main_box->add(new NTKLabel("", "neue Positionen: ".$new_position_count), 200, 0, "background-color: #dfe7f3;");
  30. // now we should have added all bills let's delete them remote
  31. $bill_net->clearTable();
  32. $bill_product_net->clearTable();
  33. ?>