## Merubah harga per Unit
Hi Team,
Minta tolong untuk No order dibawah ini, Diubah harga per-unit nya tolong di sesuaikan dengan yg ini ya :
Untuk grand total dan tagihan saat ini nya minta tolong disamakan juga ya
paper bowl : 1.103
food pail : 1.030
lunch box : 1.150
gelas pp : 440
Croffle box : 1.420
PA230227BC02
PA2302258FAC
PA23022747DD
PA2303018E8C
PA23030155B6
## rename id invoice
https://platform.printerous.com/backend/invoice-monitoring/48688/download.pdf?disposition=inline
```ruby=
order = Order.find_by(number: 'PA230224DE23')
order.invoices.pluck(:id)
number = 'PA230224DE23-3'
old_price = '1133'.to_f
new_price = '1030'.to_f
order_item = OrderItem.find_by(number: number)
order = Order.find_by(id: order_item.order_id)
po_id = order.partner_order_items.first.partner_order_id
po = PartnerOrder.find(po_id)
po_item = PartnerOrderItem.find_by(order_item_id: order_item.id)
# Update order item
order_item.price = new_price
order_item.subtotal = order_item.quantity * new_price
order_item.tax = order_item.quantity * new_price * 0.11
order_item.grand_total = order_item.quantity * new_price
order_item.save!
# Update order
order.subtotal = OrderItem.where(order_id: order.id).sum(&:subtotal)
order.tax = order.subtotal * 0.11
order.grand_total = order.subtotal + order.shipping_fee
order.save!
# Update partner order item
po_item.total_price = po_item.quantity * new_price
po_item.save!
# Update partner order
po.price = PartnerOrderItem.where(partner_order_id: po_id).sum(&:total_price)
po.tax = po.price * 0.11
po.save!
invoice_item = InvoiceItem.find_by(order_item_id: order_item.id)
if invoice_item.present?
invoice_item.subtotal = order_item.subtotal
invoice_item.grand_total = order_item.grand_total
invoice_item.save
grand_total = order.subtotal + order.shipping_fee - order.discount
grand_total += order.tax if order.tax_policy == 'tax_exclusive'
main_invoice = invoice_item.invoice_main
main_invoice.subtotal = order.subtotal
main_invoice.grand_total = order.grand_total
main_invoice.price = grand_total
main_invoice.save!
end
number = main_invoice.number
number = 'INV/220726/66A1'
invoice = Invoice.where(number: number)
invoice.update_all(tax_template: :show_tax, tax_policy: :tax_exclusive)
# change tagihan saat ini
price = 5352420
tagihan_saat_ini = price.to_f
invoice.update_all(price: tagihan_saat_ini)
number = 'INV/220916/C491'
price = 3756899.95
tagihan_saat_ini = price.to_f
invoice = Invoice.where(number: number)
invoice.update_all(price: tagihan_saat_ini)
minta tolong buatin invoice manual untuk no order PA2202167EAD
Box Motahuaja - 10000pcs
Sticker Label MotahuAja - 10050pcs
PPN 11% ya
thankyou
### generate invoice
items = [
{
number: 'PA2202167EAD-2',
quantity: 10000
},
{
number: 'PA2202167EAD-1',
quantity: 10050
},
]
subtotal = discount = shipping_fee = 0
order = Order.find_by number: 'PA2202167EAD'
integration = [{ id: order.id, type: 'Order' }]
integration = []
order_items = []
items.each do |item|
order_item = OrderItem.find_by number: item[:number]
item_subtotal = item[:quantity] * order_item.price
subtotal += item_subtotal
# if order.blank?
order = order_item.order
# integration << { id: order.id, type: 'Order' }
# end
order_items << item
end
number = Invoice.generate_number
billing_address = order.order_items.map(&:billing_address).reject(&:blank?).first
tax_policy = :tax_inclusive
slug = SecureRandom.hex.slice(0, 4).upcase
term_of_payment = order.order_terms
top_settlement = term_of_payment.size > 1 ? term_of_payment.last : term_of_payment.first
top_type = order.order_terms[0][:calculation]
tax_template = :show_tax
tax_amount = (subtotal + shipping_fee - discount) * 0.11
grand_total = subtotal + shipping_fee - discount
grand_total += tax_amount if order.tax_policy == 'tax_exclusive'
invoice = InvoiceMain.create(
parent_id: nil,
number: number,
billing_address_id: billing_address.id,
billing: billing_address.address_json,
price: grand_total,
discount: discount,
tax_template: tax_template,
tax_policy: tax_policy,
term: {},
invoice_date: nil,
integration: integration,
shipping_fee: shipping_fee,
subtotal: subtotal,
grand_total: grand_total,
data: { active: true }
)
items.each do |item|
order_item = OrderItem.find_by number: item[:number]
item_subtotal = item[:quantity] * order_item.price
invoice.invoice_items.create(
order_item_id: order_item.id,
title: order_item.title,
quantity: item[:quantity],
unit: order_item.unit,
tax_policy: order_item.tax_policy,
subtotal: item_subtotal,
grand_total: item_subtotal,
integration: [{ id: order_item.id, type: 'OrderItem' }],
slug: slug
)
end
type = 'InvoiceSettlement'
status = top_settlement.name == 'CIA' ? 'submitted' : 'draft'
value = top_settlement.value.to_f
price = top_type == 'percentage' ? value * grand_total / 100 : value
terms = {
id: top_settlement.term_id,
term: top_settlement.name,
value: value,
days: top_settlement.baseline_due,
status: status,
price: price
}
invoice_number = number
due_date = nil
invoice_date = nil
if terms[:status] != 'draft'
invoice_date = Time.now
due_date = DateTime.now + terms[:days].days
end
invoice_child = type.constantize.find_or_initialize_by(parent_id: invoice.id)
invoice_child.parent_id = invoice.id
invoice_child.number = invoice_number
invoice_child.billing_address_id = billing_address.id
invoice_child.billing = billing_address.address_json
invoice_child.price = terms[:price]
invoice_child.tax_template = tax_template
invoice_child.tax_policy = tax_policy
invoice_child.term = {}
invoice_child.invoice_date = invoice_date
invoice_child.due_date = due_date
invoice_child.status = terms[:status]
invoice_child.integration = [{ id: order.id, type: 'Order' }, { id: terms[:id], type: 'OrderTerm' }]
invoice_child.top_terms = terms
invoice_child.data = { active: true }
invoice_child.subtotal = terms[:price]
invoice_child.grand_total = terms[:price]
invoice_child.save
get nomor invoice:
invoice.number
Download invoicenya:
https://platform.printerous.com/backend/invoice-monitoring
search by: number
Mohon dibantu untuk ubah harga order 220921CBRPUABX.
Harga COGS (PO) : Rp. 82.000 (inc ppn)
Harga Jual :
Subtotal : Rp. 102.500
Discount : Rp. 10.250
Total Price : Rp. 92.250
Terima kasih sebelumnya.
number = '220921CBRPUABX-1'
old_price = '87500'.to_f
new_price = '102500'.to_f
discount = '10250'.to_f
order_item = OrderItem.find_by(number: number, price: old_price)
order = Order.find_by(id: order_item.order_id)
po_id = order.partner_order_items.first.partner_order_id
po = PartnerOrder.find(po_id)
po_item = PartnerOrderItem.find_by(order_item_id: order_item.id)
# Update order item
order_item.price = new_price
order_item.subtotal = order_item.quantity * new_price
order_item.tax = order_item.quantity * new_price * 0.11
order_item.grand_total = order_item.quantity * new_price
order_item.save!
# Update order
order.subtotal = OrderItem.where(order_id: order.id).sum(&:subtotal)
order.tax = order.subtotal * 0.11
order.grand_total = (order.subtotal + order.shipping_fee) - discount
order.save!
# Update partner order item
po_item.total_price = po_item.quantity * new_price
po_item.save!
# Update partner order
po.price = PartnerOrderItem.where(partner_order_id: po_id).sum(&:total_price)
po.tax = po.price * 0.11
po.save!
```
### create invoice qoala
```ruby=
Dir['app/jobs/qoala/*'].each { |file| load file }
sheet_id = "1IQ5XrfixicGmMAzGrjhtAmob3DQvnEOP8KsyvR78Xz4"
range = "Qoala Additional!A2:A200"
data_qoala = Gdrive::SheetReader.new(sheet_id, range).read
values = []
numbers = []
starting_row = 2
index = 0
need_invoice = data_qoala.select { |row| row[0].present? }
numbers += need_invoice.collect { |row| row[0] }
data_qoala.each_with_index do |data|
gsheet_row = starting_row + index
next if numbers.exclude?(data[0])
values << {
range: "E#{gsheet_row}",
values: nil
}
index+=1
end
if numbers.present?
# Create order terms
Qoala::OrderTermOfficer.new(numbers).perform
invoice_main = Qoala::InvoiceMainOfficer.new(numbers).perform
Qoala::InvoiceChildOfficer.new(invoice_main.id).perform
puts "Invoice Created... | #{invoice_main.number}"
values.map! do |row|
row[:values] = [invoice_main.number]
row
end
puts 'Updating Gsheet values...'
Gdrive::SheetWriter.new(sheet_id, values, sheet_name: 'Qoala Additional!', value_input_option: nil).write
end
### sync file sweetescape
order_item = OrderItem.find_by(number: 'PCSE22A114FDD-II-01')
project_data = ActiveSupport::JSON.decode(order_item.data['project_data'])
image_url = project_data['images'].pluck('h_url')
```