-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_inventoryAjustment.php
95 lines (70 loc) · 1.92 KB
/
example_inventoryAjustment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
require_once("KoronaApi.class.php");
$token = "your token";
$orgNo = "139";
$api = new KoronaApi($token);
$org = $api->getObjByNumber("organizationalUnits",$orgNo);
echo "Org: ".$org->name."\r\n\n";
file_put_contents("error.txt","# import \r\n",FILE_APPEND);
file_put_contents("404.txt","# import \r\n",FILE_APPEND);
$row = 0;
$importNo = 2000;
$items = array();
if (($handle = fopen("my_csv_file.csv", "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$sku = trim($data[0]);
$count = intval(trim($data[1]));
echo "sku: $sku \t\t count: $count ";
try {
$result = $api->getObjByNumber("products",$sku);
if (isset($result->uuid) && !empty($result->uuid)) {
$adjItem = (object) array();
$adjItem->product = $result->uuid;
$adjItem->additionalGoods = $count;
$items[] = $adjItem;
echo "OK -> ".$result->name." \r\n";
$row++;
}
else
file_put_contents("error.txt","$sku;$count\r\n",FILE_APPEND);
}
catch(Exception $e)
{
echo "404 \n";
file_put_contents("404.txt","$sku;$count\r\n",FILE_APPEND);
}
if (count($items) >= 100)
{
echo "post list \n\n";
$adj = (object) array();
$adj->reason = "import";
$adj->warehouse = $org->uuid;
$adj->externalId = "import-$importNo";
$adj->number = $importNo;
$adj->time = date("Y-m-d")."T".date("h:i:sP");
$adj->items = $items;
//echo json_encode($adj)."\n\n\n";
$result = $api->post("stocks/adjust/", $adj);
$items = array();
$importNo++;
}
}
if (count($items) > 0)
{
echo "post list \n\n";
$adj = (object) array();
$adj->reason = "import";
$adj->warehouse = $org->uuid;
$adj->externalId = "import-$importNo";
$adj->number = $importNo;
$adj->time = date("Y-m-d")."T".date("h:i:sP");
$adj->items = $items;
//echo json_encode($adj)."\n\n\n";
$result = $api->post("stocks/adjust/", $adj);
$items = array();
}
fclose($handle);
}
?>