-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdocs.php
132 lines (107 loc) · 4.09 KB
/
docs.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
include'vendor/autoload.php';
$app = new Warehouse();
switch ($app->stickyGET('type')) {
case 'sale':
$m = new Sale($app->db);
break;
case 'purchase':
$m = new Purchase($app->db);
break;
default:
$app->layout->add(['Message','Cannot recognize type', 'error']);
exit;
// not sure
}
if ($app->stickyGET('due')) {
// must only show documents that are due
$m->addCondition('is_paid', false);
$m->addCondition('status', 'posted');
}
$type = $app->stickyGET('type');
$dir = $app->stickyGET('dir');
if ($id = $app->stickyGET('id')) {
$m->load($id);
$bc = $app->layout->add(['ui'=>'segment'])->add(new ui\Breadcrumb($m['ref']));
$bc->addCrumb(get_class($m).'s', ['id'=>false]);
$cc = $app->layout->add('Columns');
$c = $cc->addColumn(4);
$print = $app->layout->add('VirtualPage');
$print->set(function($page) use($m) {
$page->app->initLayout('Centered', ['template'=>new \atk4\ui\Template('{$Content}')]);
$page->app->layout->template->tryDel('Header');
$page->add(new ui\DocView())->setModel($m);
});
$card = $c->add(new ui\Card());
$card->setModel($m);
$card->withEdit();
$card->add(['Button', 'Print', 'icon'=>'print'], 'Buttons')->on('click', new \atk4\ui\jsExpression(
'window.open([], [], [])',
[$print->getURL(), 'print', 'width=1000, height=1100, location=no, menubar=no, scrollbars=yes,toolbar=no,titlebar=no']
));
if ($m['status'] == 'draft') {
$reload_url = $app->url();
$card->add(['Button', 'Make Posted', 'blue fluid'])->on('click', function() use ($m, $reload_url) {
$m->makePosted();
return new \atk4\ui\jsExpression('document.location = []', [$reload_url]);
});
}
if ($m['status'] == 'posted') {
$reload_url = $app->url();
$card->add(['Button', 'Make Paid', 'green fluid'])->on('click', function() use ($m, $reload_url) {
$m->saveAndUnload(['status'=>'paid']);
return new \atk4\ui\jsExpression('document.location = []', [$reload_url]);
});
}
if($m->hasElement('partner_id')) {
$card = $c->add(new ui\Card());
$card->setModel($m->ref('partner_id'));
$card->withEdit();
}
$c = $cc->addColumn(12);
if ($m['status'] == 'draft' || $m['status'] == 'validated') {
$f = new ui\LineForm();
$f->which_price = $_GET['type'];
$lines = $c->add([
'CRUD',
'paginator'=>false,
'formEdit'=>$f,
'formCreate'=>$f,
]);
} else {
$lines = $c->add(['Grid', 'paginator'=>false]);
}
$lines->add(['Header', 'Invoice Lines']);
$lines->setModel($m->ref('Lines'));
$lines->menu->addItem('Back')->link($app->url(['id'=>false]));
$lines->table->addClass('small');
if ($m['status'] != 'draft') {
$c->add(['Header', 'Related stock effect']);
$related = $c->add(['Grid', 'menu'=>false, 'paginator'=>false]);
$stock = new Stock($app->db);
$stock->join('related.stock_id')->addField('document_id');
$stock->addCondition('document_id', $m->id);
$related->setModel($stock);
}
exit;
}
$gr = $app->layout->add(['CRUD', 'ops'=>['u'=>false]]);
$gr->fieldsGrid = ['ref','date','partner','status', 'is_paid','net','total'];
$gr->setModel($m);
$gr->addDecorator('status', new \atk4\ui\TableColumn\Status(['positive'=>['posted', 'paid'], 'disabled'=>['draft']]));
$gr->table->addClass('selectable');
$gr->table->addStyle('cursor', 'pointer');
$gr->table->on('click', 'tr', new \atk4\ui\jsExpression('document.location=[]+"&id="+[]', [$app->url(), $gr->table->jsRow()->data('id')]))
->addClass('active')
->siblings()->removeClass('active');
//$gr->setModel(clone $m, ['name', 'type', 'phone']);
/*
$card = $c->addColumn()->add(new ui\Card());
$card->setModel($m);
if ($m->loaded()) {
$card->add(['Button', 'Edit', 'icon'=>'edit'], 'Buttons')->link(['action'=>'edit']);
$card->add(['Button', 'Delete', 'icon'=>'red delete'], 'Buttons')->link(['action'=>'delete']);
} else {
$card->template->del('has_buttons');
}
*/