PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.3.13
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.3.13
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / modules / accounting / includes / cli / commands.php

commands.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.3.13, at modules/accounting/includes/cli/commands.php

246 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WeDevs\ERP\Accounting\CLI;
3
4 /**
5 * Accounting CLI class
6 */
7 class Commands extends \WP_CLI_Command {
8
9 function new_customers() {
10 $results = [];
11
12 $fake_customers = [
13 [
14 'first_name' => 'Beverly',
15 'last_name' => 'Jefferson',
16 'email' => 'InezBSimpson@inbound.plus',
17 'company' => 'Payless Cashways',
18 'type' => 'customer',
19 'street_1' => '9880 Oleander Lane',
20 'city' => 'Dormansville',
21 'state' => 'NY',
22 'phone' => '(765) 629-3533'
23 ],
24 [
25 'first_name' => 'Jorden',
26 'last_name' => 'Stevenson',
27 'email' => 'EugeneMMatthews@inbound.plus',
28 'company' => 'The Original House of Pies',
29 'type' => 'customer',
30 'street_1' => '5853 120th Drive',
31 'city' => 'Foster',
32 'state' => 'MO',
33 'phone' => '(660) 619-4971'
34 ],
35 [
36 'first_name' => 'Christian',
37 'last_name' => 'Hale',
38 'email' => 'WilliamCRobertson@inbound.plus',
39 'company' => 'Back To Basics Chiropractic Clinic',
40 'type' => 'customer',
41 'street_1' => '9407 Ellis Drive',
42 'city' => 'Sautee Nacoochee',
43 'state' => 'GA',
44 'phone' => '(706) 673-9906'
45 ]
46 ];
47
48 foreach ( $fake_customers as $customer ) {
49 $results[] = erp_insert_people( $customer );
50 }
51
52 return $results;
53 }
54
55 function new_vendors() {
56 $results = [];
57
58 $fake_vendors = [
59 [
60 'first_name' => 'Mohammed',
61 'last_name' => 'Bridges',
62 'email' => 'DeborahRIverson@inbound.plus',
63 'company' => 'Endicott Johnson',
64 'type' => 'vendor',
65 'street_1' => '3420 Beaubien Court',
66 'city' => 'Hallandale',
67 'state' => 'FL',
68 'phone' => '(954) 201-6651'
69 ],
70 [
71 'first_name' => 'Ezequiel',
72 'last_name' => 'Rutledge',
73 'email' => 'LindaJPinkston@inbound.plus',
74 'company' => 'Country Club Markets',
75 'type' => 'vendor',
76 'street_1' => '8106 Congress Road',
77 'city' => 'Providence',
78 'state' => 'RI',
79 'phone' => '(401) 361-4590'
80 ],
81 [
82 'first_name' => 'Brad',
83 'last_name' => 'Parsons',
84 'email' => 'RaymondAReynolds@inbound.plus',
85 'company' => 'Atlas Architectural Designs',
86 'type' => 'vendor',
87 'street_1' => '1920 Dearborn Drive',
88 'city' => 'Linwood',
89 'state' => 'NY',
90 'phone' => '(585) 238-7943'
91 ]
92 ];
93
94 foreach ( $fake_vendors as $vendor ) {
95 $results[] = erp_insert_people( $vendor );
96 }
97
98 return $results;
99 }
100
101 public function delete() {
102 global $wpdb;
103 // truncate table
104 $tables = ['erp_ac_transactions', 'erp_ac_transaction_items', 'erp_ac_journals', 'erp_ac_payments'];
105 foreach ($tables as $table) {
106 $wpdb->query( 'TRUNCATE TABLE ' . $wpdb->prefix . $table);
107 }
108 \WP_CLI::success( "Table deleted successfully!" );
109 }
110
111 /**
112 * Seed the database
113 */
114 public function seed( $args ) {
115 global $wpdb, $current_user;
116
117 $supper_admin_email = get_option( 'admin_email' );
118 $current_user = get_user_by( 'email', $supper_admin_email );
119
120 // truncate table
121 $tables = ['erp_ac_transactions', 'erp_ac_transaction_items', 'erp_ac_journals'];
122 foreach ($tables as $table) {
123 $wpdb->query( 'TRUNCATE TABLE ' . $wpdb->prefix . $table);
124 }
125
126 $args = array( 'type' => 'customer' );
127 $customers = erp_get_peoples( $args );
128 $customers_id = wp_list_pluck( $customers, 'id' );
129
130 if ( ! count( $customers_id ) ) {
131 $customers_id = $this->new_customers();
132 }
133
134 // insert some sales data
135 $data_count = 10;
136
137 $sales_type = ['invoice', 'payment'];
138 $sales_ledger = [53, 54, 55];
139 $expense_type = ['payment_voucher', 'vendor_credit'];
140 $bank_accounts = [7, 62];
141
142
143 for ($i = 0; $i < $data_count; $i++) {
144 $date_due = date( 'Y-m-d', strtotime( '-' . $i . ' days' ) );
145 $date_future = date( 'Y-m-d', strtotime( '+' . $i + 7 . ' days' ) );
146 $date = [$date_future, $date_due];
147
148 $form_type = $sales_type[ array_rand( $sales_type ) ];
149 $trans_total = rand( 100, 20000 );
150 $user_id = $customers_id[ array_rand( $customers_id ) ];
151 $date = $date[ array_rand( $date ) ];
152
153 $sales = [
154 'id' => '',
155 'type' => 'sales',
156 'form_type' => $form_type,
157 'account_id' => ( $form_type == 'invoice' ) ? 1 : $bank_accounts[ array_rand( $bank_accounts ) ],
158 'status' => 'draft', //( $form_type == 'invoice' ) ? 'awaiting_payment' : 'closed',
159 'user_id' => $user_id,
160 'billing_address' => 'Dhanmondi, Dhaka',
161 'ref' => '',
162 'issue_date' => date( 'Y-m-d', strtotime( '-' . $i . ' days' ) ),
163 'due_date' => ( $form_type == 'invoice' ) ? $date : null,
164 'summary' => '',
165 'total' => $trans_total,
166 'trans_total' => $trans_total,
167 'sub_total' => $trans_total,
168 'files' => '',
169 'currency' => erp_ac_get_currency(),
170 'created_by' => 1,
171 'created_at' => current_time( 'mysql' ),
172 'partial_id' => [],
173 'items_id' => [$i => ''],
174 'journals_id' => [$i => ''],
175 'line_total' => [$trans_total]
176 ];
177
178 $sales_item = [
179 [
180 'item_id' => '',
181 'journal_id' => '',
182 'account_id' => $sales_ledger[ array_rand( $sales_ledger ) ],
183 'description' => 'Some random description',
184 'qty' => 1,
185 'unit_price' => $trans_total,
186 'discount' => 0,
187 'line_total' => $trans_total,
188 'tax' => '-1',
189 'tax_rate' => '0.00',
190 'tax_journal' => 0
191 ]
192 ];
193
194 erp_ac_insert_transaction( $sales, $sales_item );
195 }
196
197 $args = array( 'type' => 'vendor' );
198 $vendors = erp_get_peoples( $args );
199 $vendors_id = wp_list_pluck( $vendors, 'id' );
200
201 if ( ! count( $vendors_id ) ) {
202 $vendors_id = $this->new_vendors();
203 }
204
205 // insert some expense data
206 for ($i = 0; $i < $data_count; $i++) {
207 $form_type = $expense_type[ array_rand( $expense_type ) ];
208 $trans_total = rand( 100, 20000 );
209 $user_id = $vendors_id[ array_rand( $vendors_id ) ];
210
211 erp_ac_insert_transaction( [
212 'type' => 'expense',
213 'form_type' => $form_type,
214 'account_id' => ( $form_type == 'vendor_credit' ) ? 8 : $bank_accounts[ array_rand( $bank_accounts ) ],
215 'status' => 'draft', //'closed',
216 'user_id' => $user_id,
217 'billing_address' => 'Dhanmondi, Dhaka',
218 'ref' => '',
219 'issue_date' => date( 'Y-m-d', strtotime( '-' . $i . ' days' ) ),
220 'due_date' => ( $form_type == 'vendor_credit' ) ? date( 'Y-m-d', strtotime( '+' . $i + 7 . ' days' ) ) : null,
221 'summary' => '',
222 'total' => $trans_total,
223 'trans_total' => $trans_total,
224 'files' => '',
225 'currency' => '',
226 'partial_id' => [],
227 'created_by' => 1,
228 'created_at' => current_time( 'mysql' )
229 ], [
230 [
231 'account_id' => rand( 24, 49 ),
232 'description' => 'Some random description',
233 'qty' => 1,
234 'unit_price' => $trans_total,
235 'discount' => 0,
236 'line_total' => $trans_total,
237 ]
238 ] );
239 }
240
241 \WP_CLI::success( "Database has been seeded!" );
242 }
243 }
244
245 \WP_CLI::add_command( 'accounting', 'WeDevs\ERP\Accounting\CLI\Commands' );
246