Packages can be marked hand delivered

main
Ashelyn Dawn 5 years ago
parent 5648a1b31a
commit c5425d8cb4

@ -162,3 +162,8 @@ router.post('/:uuid/ship/tracking', ensureAdmin, parseJSON, async (req, res) =>
const order = await db.order.setTracking(req.params.uuid, req.body.code, req.body.date || null) const order = await db.order.setTracking(req.params.uuid, req.body.code, req.body.date || null)
res.json(order) res.json(order)
}) })
router.post('/:uuid/ship/delivery', ensureAdmin, parseJSON, async (req, res) => {
const order = await db.order.setDelivery(req.params.uuid, req.body.description, req.body.date || null)
res.json(order)
})

@ -250,3 +250,11 @@ order.setTracking = (uuid, trackingCode, shipDate) =>
returnType: 'order', returnType: 'order',
single: true single: true
}) })
order.setDelivery = (uuid, description, deliveryDate) =>
dbUtil.executeFunction({
name: 'set_delivery_by_hand',
params: [uuid, description, deliveryDate],
returnType: 'order',
single: true
})

@ -943,3 +943,50 @@ begin
return query select * from sos.v_order where order_uuid = _order_uuid; return query select * from sos.v_order where order_uuid = _order_uuid;
end; $function$; end; $function$;
create or replace function sos.set_delivery_by_hand(_order_uuid uuid, _description text, _date_delivered timestamptz)
returns setof sos.v_order
language plpgsql
as $function$
declare
_delivery_uuid uuid;
begin
-- Ensure order has no delivery
select order_delivery_uuid into _delivery_uuid
from sos."order" where order_uuid = _order_uuid;
if _delivery_uuid is not null then
raise 'Order already has a delivery record';
end if;
-- Create delivery
insert into sos."delivery" (
delivery_type
) values (
'hand_delivered'
) returning delivery_uuid into _delivery_uuid;
-- Default date
if _date_delivered is null then
_date_delivered := now();
end if;
-- Create delivery subtype record
insert into sos."delivery_hand_delivered" (
delivery_uuid,
delivery_type,
delivery_description,
delivery_date_delivered
) values (
_delivery_uuid,
'hand_delivered',
_description,
_date_delivered
);
-- Update order
update sos."order" set
order_delivery_uuid = _delivery_uuid
where order_uuid = _order_uuid;
return query select * from sos.v_order where order_uuid = _order_uuid;
end; $function$;

@ -15,10 +15,10 @@ export default function Order({order}){
return ( return (
<> <>
<ActionBar title="Order Details" actions={[ <ActionBar title="Order Details" actions={!order.delivery && [
// {label: 'Ship via Easypost', url: `/admin/orders/${order.uuid}/ship/easypost`}, // {label: 'Ship via Easypost', url: `/admin/orders/${order.uuid}/ship/easypost`},
{label: 'Enter Tracking', url: `/admin/orders/${order.uuid}/ship/tracking`}, {label: 'Enter Tracking', url: `/admin/orders/${order.uuid}/ship/tracking`},
// {label: 'Mark Delivered', url: `/admin/orders/${order.uuid}/ship/delivery`} {label: 'Mark Delivered', url: `/admin/orders/${order.uuid}/ship/delivery`}
]}/> ]}/>
<h2>Order for {capitalizeName(order.address.name)}</h2> <h2>Order for {capitalizeName(order.address.name)}</h2>

@ -0,0 +1,26 @@
import React, {useState} from 'react'
import Router from 'next/router'
import ActionBar from '~/components/admin/actionBar'
import {FormController, DateInput, TextArea, Button} from '~/components/form'
EnterDelivery.getInitialProps = async ({ctx: {axios, query: {id}}}) => {
const {data: order} = await axios.get(`/api/orders/${id}`)
return {order}
}
export default function EnterDelivery({order}){
return (
<>
<ActionBar title="Mark Delivered"/>
<FormController afterSubmit={() => Router.push(`/admin/orders/${order.uuid}`)} url={`/api/orders/${order.uuid}/ship/delivery`}>
<p>Use this to enter delivery information for packages delivered in-person or at a con.</p>
<p>In case we ever have future corespondence with this person, please be sure to describe where, when, and to who you gave the package.</p>
<TextArea label="Description" validate={val => val.length > 0} type="text" name="description" hint="Please describe how and where you delivered the order to them" />
<DateInput label="Delivery Date" placeholder="Today" name="date" />
<Button type="submit">Submit</Button>
</FormController>
</>
)
}

@ -15,6 +15,7 @@ export default function EnterTracking({order}){
<ActionBar title="Enter Tracking"/> <ActionBar title="Enter Tracking"/>
<FormController afterSubmit={() => Router.push(`/admin/orders/${order.uuid}`)} url={`/api/orders/${order.uuid}/ship/tracking`}> <FormController afterSubmit={() => Router.push(`/admin/orders/${order.uuid}`)} url={`/api/orders/${order.uuid}/ship/tracking`}>
<p>Use this to enter tracking information for packages shipped by-hand (via USPS)</p>
<Input label="Tracking Code" validate={val => val.length > 0} type="text" name="code" hint="Please enter the USPS Tracking code" /> <Input label="Tracking Code" validate={val => val.length > 0} type="text" name="code" hint="Please enter the USPS Tracking code" />
<DateInput label="Ship Date" placeholder="Today" name="date" /> <DateInput label="Ship Date" placeholder="Today" name="date" />
<Button type="submit">Submit</Button> <Button type="submit">Submit</Button>

Loading…
Cancel
Save